fix: judge concurrency safety#329
Open
gsonntag wants to merge 4 commits into
Open
Conversation
MichaelZhao21
requested changes
May 22, 2026
Comment on lines
+443
to
+445
| state.Clock.Mutex.Lock() | ||
| running := state.Clock.State.Running | ||
| state.Clock.Mutex.Unlock() |
Contributor
There was a problem hiding this comment.
I don't think it's necessary to lock the clock mutex here. Because the running state is a boolean, it shouldn't need to be locked for reading.
Comment on lines
+731
to
+735
| // IMPORTANT: do NOT call ctx.JSON inside the callback. Mongo's | ||
| // session.WithTransaction retries the callback on | ||
| // TransientTransactionError (which includes WriteConflict). If we | ||
| // wrote the response on a doomed first attempt, a successful retry | ||
| // would still leave the client looking at the 500. |
Contributor
There was a problem hiding this comment.
I feel like we don't need to explain all of this here; perhaps just including the explanation in the PR/commit is good enough and just adding a note to not call ctx.JSON in the callback. The same comment goes for the top of the callback for /judge/next.
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.
Description
Fixes concurrency bugs in judge assignment and scoring.
This updates
/judge/nextto re-read the judge inside the transaction before assigning a new project, so concurrent requests cannot assign multiple projects from a stale middleware snapshot. It also preserves the existing behavior of returning an already-assigned current project even when judging is paused or deliberation mode is enabled.This updates
/judge/finishto re-read the judge inside the transaction before scoring, so concurrent finish requests cannot duplicate the same project inseen_projectsor double-increment project seen counts.It also preserves Mongo transaction retry behavior by wrapping transaction errors with
%winUpdateAfterSeen, so transient transaction labels survive error wrapping.Fixes
N/A
Type of Change
Delete options that do not apply:
Is this a breaking change?