mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
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 <bsbs8645@snu.ac.kr>
This commit is contained in:
parent
a8a7116395
commit
e5c5e1897d
1 changed files with 6 additions and 4 deletions
|
|
@ -119,10 +119,11 @@ func (journal *journal) load(add func([]*types.Transaction) []error) error {
|
||||||
|
|
||||||
func (journal *journal) setupWriter() error {
|
func (journal *journal) setupWriter() error {
|
||||||
if journal.writer != nil {
|
if journal.writer != nil {
|
||||||
if err := journal.writer.Close(); err != nil {
|
err := journal.writer.Close()
|
||||||
|
journal.writer = nil
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
journal.writer = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-open the journal file for appending
|
// 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 {
|
func (journal *journal) rotate(all map[common.Address]types.Transactions) error {
|
||||||
// Close the current journal (if any is open)
|
// Close the current journal (if any is open)
|
||||||
if journal.writer != nil {
|
if journal.writer != nil {
|
||||||
if err := journal.writer.Close(); err != nil {
|
err := journal.writer.Close()
|
||||||
|
journal.writer = nil
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
journal.writer = nil
|
|
||||||
}
|
}
|
||||||
// Generate a new journal with the contents of the current pool
|
// 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)
|
replacement, err := os.OpenFile(journal.path+".new", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue