eth/downloader: fix possible data race by inconsistent field protection #20690
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.
Fixed inconsistency and also potential data race in eth/downloader/queue.go:
e.g. In eth/downloader/queue.go:
q.receiptPendPool
is read/written 10 times; 9 out of 10 times it is protected by q.lock.Lock(); 1 out of 10 times it is read without a Lock, which is in func CancelReceipts() on L579.A data race may happen when
CancelReceipts()
and other func likeRevoke()
are called in parallel.The fix is to move lock from func
cancel()
to its callerCancelReceipts()
.The other bugs and fixes are similar.
Note that there is an FP for eth/downloader/peer.go in PR 20650. I remove the changes in peer.go and start a new PR here.