-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core, miner, rpc, eth: fix goroutine leaks in tests #24211
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -800,8 +800,12 @@ func (bc *BlockChain) Stop() { | |
|
||
for _, offset := range []uint64{0, 1, TriesInMemory - 1} { | ||
if number := bc.CurrentBlock().NumberU64(); number > offset { | ||
recent := bc.GetBlockByNumber(number - offset) | ||
|
||
num := number - offset | ||
recent := bc.GetBlockByNumber(num) | ||
if recent == nil { | ||
log.Error("Failed to get block", num) | ||
continue | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'd rather revert this -- is this path triggered by the tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I could tell, the tests didn't trigger this path, so I have reverted this change. If this happens, it indicates that something is seriously wrong, either our blockchain is corrupt, or the database is closed. |
||
log.Info("Writing cached state to disk", "block", recent.Number(), "hash", recent.Hash(), "root", recent.Root()) | ||
if err := triedb.Commit(recent.Root(), true, nil); err != nil { | ||
log.Error("Failed to commit recent state trie", "err", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1779,6 +1779,7 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) { | |
SnapshotLimit: 0, // Disable snapshot by default | ||
} | ||
) | ||
defer engine.Close() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to close the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right it can't be necessary, but doing it is more correct, so I'd rather just keep it htere |
||
if snapshots { | ||
config.SnapshotLimit = 256 | ||
config.SnapshotWait = true | ||
|
@@ -1836,25 +1837,25 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) { | |
} | ||
defer db.Close() | ||
|
||
chain, err = NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{}, nil, nil) | ||
newChain, err := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{}, nil, nil) | ||
if err != nil { | ||
t.Fatalf("Failed to recreate chain: %v", err) | ||
} | ||
defer chain.Stop() | ||
defer newChain.Stop() | ||
|
||
// Iterate over all the remaining blocks and ensure there are no gaps | ||
verifyNoGaps(t, chain, true, canonblocks) | ||
verifyNoGaps(t, chain, false, sideblocks) | ||
verifyCutoff(t, chain, true, canonblocks, tt.expCanonicalBlocks) | ||
verifyCutoff(t, chain, false, sideblocks, tt.expSidechainBlocks) | ||
verifyNoGaps(t, newChain, true, canonblocks) | ||
verifyNoGaps(t, newChain, false, sideblocks) | ||
verifyCutoff(t, newChain, true, canonblocks, tt.expCanonicalBlocks) | ||
verifyCutoff(t, newChain, false, sideblocks, tt.expSidechainBlocks) | ||
|
||
if head := chain.CurrentHeader(); head.Number.Uint64() != tt.expHeadHeader { | ||
if head := newChain.CurrentHeader(); head.Number.Uint64() != tt.expHeadHeader { | ||
t.Errorf("Head header mismatch: have %d, want %d", head.Number, tt.expHeadHeader) | ||
} | ||
if head := chain.CurrentFastBlock(); head.NumberU64() != tt.expHeadFastBlock { | ||
if head := newChain.CurrentFastBlock(); head.NumberU64() != tt.expHeadFastBlock { | ||
t.Errorf("Head fast block mismatch: have %d, want %d", head.NumberU64(), tt.expHeadFastBlock) | ||
} | ||
if head := chain.CurrentBlock(); head.NumberU64() != tt.expHeadBlock { | ||
if head := newChain.CurrentBlock(); head.NumberU64() != tt.expHeadBlock { | ||
t.Errorf("Head block mismatch: have %d, want %d", head.NumberU64(), tt.expHeadBlock) | ||
} | ||
if frozen, err := db.(freezer).Ancients(); err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.