Repository navigation
eth/downloader: stop snap sync when the result queue closes empty - #2477
Open
Amirhosein wants to merge 1 commit into
Open
Amirhosein wants to merge 1 commit into
Amirhosein wants to merge 1 commit into
Conversation
When the result queue closes before a pivot block is committed or held (oldPivot == nil), Results(true) returns an empty slice. Previously, the loop proceeded to evaluate results[len(results)-1].Header, causing an index out of range [-1] panic. Cancel state sync and return early when results is empty and oldPivot is nil: if sync.Cancel() returns a non-cancellation error (e.g. from closeOnErr), surface that error; otherwise return errCanceled so callers can surface fetcher errors.
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.
Summary
Fixes an
index out of range [-1]panic inprocessSnapSyncContentwhen the result queue closes before a pivot block has been committed or held (oldPivot == nil).When
queue.Close()is called whilepivotHeaderis still uncommitted andcancelChis open:d.queue.Results(true)unblocks and returns an empty slice ([]*fetchResult{}).latest := results[len(results)-1].Header, indexing into-1and panicking.With this change, when
len(results) == 0andoldPivot == nil:sync.Cancel()is invoked. If state sync failed for a real reason (e.g. queue closed bycloseOnErr), that underlying non-cancellation error is returned.errCanceledis returned so that caller routines (such asspawnSync) can prioritize fetcher errors (such aserrNoPeers).Note: This PR addresses observation A reported in #2441 (the empty results queue panic during snap sync). Protocol receipt size limits (>10 MiB) are out of scope.
Executed tests
TestProcessSnapSyncContentEmptyQueuecovering:BareQueueShutdown: clean queue closure with healthy state sync returnserrCanceled.StateSyncFailure: queue closure triggered by a state sync failure returns the underlying error.CommittedWithEmptyQueue: empty queue when already committed preserves the normal exit path.go test -v -race ./eth/downloader -run TestProcessSnapSyncContentEmptyQueue(passed, 0 race warnings).go test -short ./eth/downloader(all passed).Rollout notes
Non-breaking bug fix, backwards-compatible, not consensus-affecting.