From d13fe43e19a82785e1cec8f275e23388bb91975f Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Thu, 28 Mar 2019 15:44:14 +0100 Subject: [PATCH] wal: fix file close don't defer in a loop --- internal/wal/wal.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/wal/wal.go b/internal/wal/wal.go index 98c9de8..c5fec24 100644 --- a/internal/wal/wal.go +++ b/internal/wal/wal.go @@ -828,7 +828,6 @@ func (w *WalManager) checkpoint(ctx context.Context) error { if err != nil { return err } - defer walFile.Close() dec := json.NewDecoder(walFile) for { var action *Action @@ -839,13 +838,16 @@ func (w *WalManager) checkpoint(ctx context.Context) error { break } if err != nil { + walFile.Close() return err } if err := w.checkpointAction(ctx, action); err != nil { + walFile.Close() return err } } + walFile.Close() w.log.Debugf("updating wal to state %q", WalStatusCheckpointed) walData.WalStatus = WalStatusCheckpointed