fix: coalesce concurrent per-AZ placement group creation in mpicohort - #520
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Actuator.ensurePlacementGroup released its lock between checking pgCreated[az] and calling CreatePlacementGroup, so concurrent cohort members launching into the same newly-visited AZ (the normal case — a round launches N members at once) could each observe "not created yet" and each issue their own CreatePlacementGroup call, defeating the once-per-AZ design meant to avoid the ~30s availability poll per member. Fixed by coalescing concurrent same-AZ callers onto a single in-flight create via a per-AZ done-channel (pgOnce), while leaving different AZs unserialized against each other. Added TestEnsurePlacementGroup_Concurrent (50 concurrent callers, same AZ) and TestEnsurePlacementGroup_ConcurrentDifferentAZsNotSerialized. Verified the former fails reliably against the pre-fix code (50/50 calls went through) and passes with the fix, under -race -count=20. Fixes #514
scttfrdmn
force-pushed
the
fix/514-placement-group-race
branch
from
August 19, 2026 05:14
b8b37ff to
437643a
Compare
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
Actuator.ensurePlacementGroup(pkg/mpicohort/adapter.go) released its mutex between checkingpgCreated[az]and callingCreatePlacementGroup, a classic check-then-act race. A cohort round launches N members concurrently, so multiple goroutines commonly race into this function for the same AZ at once — before the fix, more than one could observe "not created yet" and each callCreatePlacementGroup, defeating the once-per-AZ design that exists specifically to avoid the ~30s availability poll for every member of a round.TestActuator_PerAZPlacementGroup(AZ-b PG created 2 times, want 1) — confirmed not reproducible locally with-count=5prior to this fix, consistent with a genuine race exposed only by CI's heavier scheduling/load, per the issue.CreatePlacementGroupcall via a per-AZ done-channel (pgOnce): the first caller in does the create, the rest wait on its result. Callers for different AZs are not serialized against each other (verified by a dedicated test with a generous timing bound).golang.org/x/sync/singleflight(already a transitive dep) to keep the change self-contained to the existingpgMu-guarded state, rather than introducing a second synchronization primitive for one call site.Test plan
go build ./...,go vet ./pkg/mpicohort/...go test ./pkg/mpicohort/... -race -count=20— all green, including the previously-flakyTestActuator_PerAZPlacementGroupTestEnsurePlacementGroup_Concurrent(50 concurrent callers for one AZ, with an artificial delay inside the fakeCreatePlacementGroupto reliably widen the race window — a fast in-memory fake without it may not interleave even with the race present, which is exactly why this only flaked in CI) andTestEnsurePlacementGroup_ConcurrentDifferentAZsNotSerialized.TestEnsurePlacementGroup_Concurrentfails reliably (50/50CreatePlacementGroupcalls went through) against the pre-fix code, and passes with the fix, under-race -count=20.golangci-lint run ./pkg/mpicohort/...— 0 issues[Unreleased]Fixes #514