Conversation
A deferred close only runs when the goroutine returns, and the for-range right below it is the channel's only reader: it can never return. Sends from the block import paths and from miner/worker.go would race the close if it ever did.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
gzliudan
requested review from
AnilChinchawale,
anunay-xin,
benjamin202410,
liam-lai and
wanwiset25
September 16, 2026 17:06
anunay-xin
approved these changes
Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
startNodestarts a goroutine that validates this node's masternode and then reconciles the staking state at every epoch switch. Its last two statements are adjacent:The deferred close can never run. A
deferruns when the function returns, and nothing after it can return: thefor rangethat follows is the only remaining statement and it consumes signals until the channel is closed and drained. Reaching thedefertherefore requires the channel to be closed already - by which point a second close would be a different failure anyway. It is dead code, and it has been since the loop was written.What makes it worth removing is that it states a guarantee the surrounding code does not provide.
core.CheckpointChis a package level channel whose senders outlivestartNodeand everything in it:core/blockchain.gosends on every epoch switch block reaching the head, from bothinsertChainandinsertBlock, with the chain mutex held;miner/worker.gosends from the goroutine that drains the mined-block queue.None of them is aware of this goroutine's lifetime. Any future change that gives this loop an exit - a shutdown signal, an error return - would turn the
deferinto a race, and a close concurrent with one of those sends panics with "send on closed channel". Leaving the close there invites exactly that change; leaving nothing there states the truth, which is that this channel lives as long as the process and is only ever drained.Introduced together with the loop in
9f5cba7dc("update new set of masternodes at end of each epoch (distance = m1Gap)", 2018-09-30), and never touched since.Fix
Drop the
deferand replace it with a comment recording why the channel is deliberately never closed: who sends on it, that this loop is its only reader, and that a close could only race a send. No sender, no receiver, and no behaviour changes - the statement removed could never execute.Verification
gofmtclean;go build ./...andgo vet ./cmd/XDCpass.cmd/XDCis not covered by the test suite in any case. The change is confined to one file incmd/XDC, so nothing else needed re-verification.Attribution
A pre-existing cleanup, found while reading the checkpoint plumbing for #2534 and #2535; it is unrelated to those two issues and does not depend on any work in flight.
The same cleanup has also been carried on the
#2534/#2535line of work (de396c3a7onfix-issue-2534-2535, opened as #2566) so that branch could keep signalling checkpoints safely. Whichever of the two lands first, the other should drop its copy on rebase - they touch the same line.