[queue runner] Fix db races in substituting steps.#1790
Open
Mic92 wants to merge 1 commit into
Open
Conversation
1034662 to
254d37d
Compare
254d37d to
855e192
Compare
Member
Author
|
Looks good now:
|
5626e85 to
caac547
Compare
stepnr is computed as MAX(stepnr) + 1 inside the insert. Transactions inserting steps for the same build at the same time pick the same number: the loser blocks on the winner's uncommitted unique-index entry, hits ON CONFLICT DO NOTHING once the winner commits and retries. The queue monitor substitutes outputs of a build concurrently (buffer_unordered(10), also across derivations of the same build), so this happened constantly. Each blocked insert held a connection from the pool. Observed while processing a 120-build nixos-small evaluation against an empty binary cache: 260 slow statement warnings, single inserts taking up to 15s and unrelated queries waiting 3s for a pool connection. Take pg_advisory_xact_lock(class, build_id) before the insert. Writers for the same build now queue up for the duration of a short transaction instead of fighting over the same stepnr.
30d85e5 to
51a926a
Compare
Ericson2314
approved these changes
Jun 11, 2026
Conni2461
approved these changes
Jun 16, 2026
| conn | ||
| } | ||
|
|
||
| fn substitution_step(build_id: i32, drv_path: &StorePath) -> InsertBuildStep<'_> { |
Member
There was a problem hiding this comment.
if we only need this function for test we can mark restrict it to test
| assert_eq!(result, Some(sp("final-result"))); | ||
| } | ||
|
|
||
| async fn replica_conn(pool: &sqlx::PgPool) -> Connection { |
Member
There was a problem hiding this comment.
if we only need this function for test we can mark restrict it to test
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.
I am currently testing nixos minimal in a private staging deployment.
I found this race in journal of my builder:
Still testing the fix.
Check the commits for more details.