Skip to content

[SharovBot] fix race condition in shutter decryption keys wait#21898

Closed
erigon-copilot[bot] wants to merge 1 commit into
mainfrom
erigon-copilot/fix-shutter-block-building-flaky-test
Closed

[SharovBot] fix race condition in shutter decryption keys wait#21898
erigon-copilot[bot] wants to merge 1 commit into
mainfrom
erigon-copilot/fix-shutter-block-building-flaky-test

Conversation

@erigon-copilot

Copy link
Copy Markdown
Contributor

Summary

  • Fix race condition in DecryptedTxnsPool.Wait() where context timeout and decryption mark arrival could race, causing the pool to miss marks that arrived just as the deadline expired.
  • On DeadlineExceeded in Pool.ProvideTxns(), fall through to check DecryptedTxns(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, return nil instead of ctx.Err().

txnprovider/shutter/pool.go: On DeadlineExceeded, instead of returning early with the secondary provider's transactions, fall through to the existing DecryptedTxns(decryptionMark) lookup which handles late-arriving marks correctly.

Test plan

  • TestShutterBlockBuilding passes 10 consecutive times without failure
  • No *_test.go files modified
  • go build ./... passes

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on context.DeadlineExceeded, instead continuing to the DecryptedTxns(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
}
@taratorio

Copy link
Copy Markdown
Member

Closing since there is no link to a failing CI run in the PR. We should not be reviewing changes blindly.

@taratorio taratorio closed this Jun 25, 2026
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.

2 participants