fix(pxe): prevent contract sync deadlock on nested syncs#23951
Merged
Conversation
Collaborator
Flakey Tests🤖 says: This CI run detected 1 tests that failed, but were tolerated due to a .test_patterns.yml entry. |
mverzilli
approved these changes
Jun 9, 2026
mverzilli
left a comment
Contributor
There was a problem hiding this comment.
Oof, very nice catch. How did you stumble upon this?
Contributor
Author
|
I got the deadlock here: #23938 |
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.
Why
The contract sync service uses a semaphore to limit how many scope syncs run concurrently. The problem: a scope sync can trigger a nested sync (a cross-contract utility call from
sync_state) that needs a slot of its own. So when 5 syncs each hold a slot and each waits on a nested sync, no slots are left for those nested syncs, and everything deadlocks. And because the semaphore was shared across the whole PXE, unrelated transactions could fill it and trigger the same deadlock.Fix
Give each sync call its own semaphore, rate-limiting only the scopes within that single call. Those scopes don't depend on each other, so bounding them can't deadlock. A nested sync builds its own limiter, so it always has a slot and can make progress. We still cap resource usage when a single call has many scopes.