From e5c5e1897d2740b42d7fd77e5730f898543a2649 Mon Sep 17 00:00:00 2001 From: cui Date: Mon, 6 Jul 2026 22:10:25 +0800 Subject: [PATCH] core/txpool/locals: nil journal writer before checking close error (#35300) This PR clears `journal.writer` immediately after `Close()` in `rotate` and `setupWriter`, before checking the error. This prevents leaving a stale file handle that could be reused if close fails. --------- Co-authored-by: Bosul Mun --- core/txpool/locals/journal.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/txpool/locals/journal.go b/core/txpool/locals/journal.go index cd2be8a794..aac59bd91f 100644 --- a/core/txpool/locals/journal.go +++ b/core/txpool/locals/journal.go @@ -119,10 +119,11 @@ func (journal *journal) load(add func([]*types.Transaction) []error) error { func (journal *journal) setupWriter() error { if journal.writer != nil { - if err := journal.writer.Close(); err != nil { + err := journal.writer.Close() + journal.writer = nil + if err != nil { return err } - journal.writer = nil } // Re-open the journal file for appending @@ -152,10 +153,11 @@ func (journal *journal) insert(tx *types.Transaction) error { func (journal *journal) rotate(all map[common.Address]types.Transactions) error { // Close the current journal (if any is open) if journal.writer != nil { - if err := journal.writer.Close(); err != nil { + err := journal.writer.Close() + journal.writer = nil + if err != nil { return err } - journal.writer = nil } // Generate a new journal with the contents of the current pool replacement, err := os.OpenFile(journal.path+".new", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)