Skip to content

core/txpool: guard nil head subscription#33970

Open
apetro2 wants to merge 1 commit intoethereum:masterfrom
apetro2:nilsub
Open

core/txpool: guard nil head subscription#33970
apetro2 wants to merge 1 commit intoethereum:masterfrom
apetro2:nilsub

Conversation

@apetro2
Copy link

@apetro2 apetro2 commented Mar 6, 2026

txpool.loop assumed SubscribeChainHeadEvent always returns a valid subscription and unconditionally deferred Unsubscribe().

That assumption is unsafe: SubscriptionScope.Track may return nil after the blockchain scope is closed, and txpool.loop starts in a goroutine, so a shutdown race can hit this path.

This PR adds a nil guard before deferring Unsubscribe(). It keeps normal behavior unchanged and prevents a panic in the race window.

A focused test (TestTxPoolLoopNilHeadSubscription) was added to exercise the nil-subscription case, and go test ./core/txpool passes (including repeated runs of the new test).

@apetro2 apetro2 requested a review from rjl493456442 as a code owner March 6, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant