From 7c17fa115a63280cbf4a2791ec88338651ab807f Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Wed, 21 Oct 2020 18:24:38 +0200 Subject: [PATCH] consensus: open target WAL as read/write during autorepair (#5536) (#5547) Fixes #5422. That turned out to be a whole lot easier than expected. Backport of #5536. --- CHANGELOG_PENDING.md | 2 +- consensus/state.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index f71bdc11d..122bcac87 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -28,5 +28,5 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - [blockchain/v2] \#5499 Fix "duplicate block enqueued by processor" panic (@melekes) - [abci/grpc] \#5520 Return async responses in order, to avoid mempool panics. (@erikgrinaker) - - [blockchain/v2] \#5530 Fix "processed height 4541 but expected height 4540" panic (@melekes) +- [consensus/wal] Fix WAL autorepair by opening target WAL in read/write mode (@erikgrinaker) diff --git a/consensus/state.go b/consensus/state.go index d1140e66a..d59a4f81d 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -328,7 +328,7 @@ func (cs *State) OnStart() error { return err } - cs.Logger.Info("WAL file is corrupted. Attempting repair", "err", err) + cs.Logger.Error("WAL file is corrupted, attempting repair", "err", err) // 1) prep work if err := cs.wal.Stop(); err != nil { @@ -345,7 +345,7 @@ func (cs *State) OnStart() error { // 3) try to repair (WAL file will be overwritten!) if err := repairWalFile(corruptedFile, cs.config.WalFile()); err != nil { - cs.Logger.Error("Repair failed", "err", err) + cs.Logger.Error("WAL repair failed", "err", err) return err } cs.Logger.Info("Successful repair") @@ -2212,7 +2212,7 @@ func repairWalFile(src, dst string) error { } defer in.Close() - out, err := os.Open(dst) + out, err := os.Create(dst) if err != nil { return err }