[SharovBot] fix race condition in shutter decryption keys wait#21898
Closed
erigon-copilot[bot] wants to merge 1 commit into
Closed
[SharovBot] fix race condition in shutter decryption keys wait#21898erigon-copilot[bot] wants to merge 1 commit into
erigon-copilot[bot] wants to merge 1 commit into
Conversation
Fix flaky TestShutterBlockBuilding by addressing two race conditions in the shutter pool's decryption key handling: 1. DecryptedTxnsPool.Wait: when the context deadline fires at nearly the same instant the decryption mark is added, the select could pick the done channel while ctx.Err() already returned DeadlineExceeded, causing a false timeout. Now the function waits for the background goroutine to finish and does a final map check before returning. 2. Pool.ProvideTxns: on DeadlineExceeded the code returned immediately to the fallback provider without checking whether the mark appeared in the pool during the race window. Now it falls through to the existing DecryptedTxns lookup, which catches marks that arrived at the timeout boundary. Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a race between decryption-mark arrival and context deadline expiration in the Shutter txn provider, ensuring late-arriving decryption marks are still considered before falling back to the base txn provider.
Changes:
- Adjust
Pool.ProvideTxns()to not immediately fall back to the base provider oncontext.DeadlineExceeded, instead continuing to theDecryptedTxns(mark)lookup. - Update
DecryptedTxnsPool.Wait()to wait for the waiter goroutine to finish on context cancellation, then re-check the map under lock to avoid missing marks arriving at the deadline boundary.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| txnprovider/shutter/pool.go | Changes timeout handling so DeadlineExceeded does not immediately trigger fallback, allowing a late decryption mark to be used. |
| txnprovider/shutter/decrypted_txns_pool.go | Waits for the background waiter to complete and re-checks decrypted-txns presence under lock after context cancellation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
64
to
68
| select { | ||
| case <-ctx.Done(): | ||
| // note the below will wake up all waiters prematurely, but thanks to the for loop condition | ||
| // in the waiting goroutine the ones that still need to wait will go back to sleep | ||
| p.decryptionCond.Broadcast() | ||
| <-done | ||
| case <-done: |
Comment on lines
+260
to
264
| } else { | ||
| decryptionMarkWaitSecs.ObserveDuration(decryptionMarkWaitStart) | ||
| decryptionMarkMissed.Inc() | ||
| return nil, err | ||
| } |
Member
|
Closing since there is no link to a failing CI run in the PR. We should not be reviewing changes blindly. |
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
DecryptedTxnsPool.Wait()where context timeout and decryption mark arrival could race, causing the pool to miss marks that arrived just as the deadline expired.DeadlineExceededinPool.ProvideTxns(), fall through to checkDecryptedTxns(decryptionMark)instead of immediately falling back to the secondary txn provider, so late-arriving marks are still used.Changes
txnprovider/shutter/decrypted_txns_pool.go: After context cancellation, wait for the background goroutine to finish (<-done), then do a final map check under lock. If the mark arrived in the meantime, returnnilinstead ofctx.Err().txnprovider/shutter/pool.go: OnDeadlineExceeded, instead of returning early with the secondary provider's transactions, fall through to the existingDecryptedTxns(decryptionMark)lookup which handles late-arriving marks correctly.Test plan
TestShutterBlockBuildingpasses 10 consecutive times without failure*_test.gofiles modifiedgo build ./...passes