wal: fix file close

don't defer in a loop
This commit is contained in:
Simone Gotti 2019-03-28 15:44:14 +01:00
parent 805099b693
commit d13fe43e19

View File

@ -828,7 +828,6 @@ func (w *WalManager) checkpoint(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
defer walFile.Close()
dec := json.NewDecoder(walFile) dec := json.NewDecoder(walFile)
for { for {
var action *Action var action *Action
@ -839,13 +838,16 @@ func (w *WalManager) checkpoint(ctx context.Context) error {
break break
} }
if err != nil { if err != nil {
walFile.Close()
return err return err
} }
if err := w.checkpointAction(ctx, action); err != nil { if err := w.checkpointAction(ctx, action); err != nil {
walFile.Close()
return err return err
} }
} }
walFile.Close()
w.log.Debugf("updating wal to state %q", WalStatusCheckpointed) w.log.Debugf("updating wal to state %q", WalStatusCheckpointed)
walData.WalStatus = WalStatusCheckpointed walData.WalStatus = WalStatusCheckpointed