fix(boatstack): concurrent first use hydrates the shared runtime exactly once - #198
Merged
Merged
Conversation
…es exactly once
After the ETXTBSY exec-retry landed, TestGuardAutoHydrationSerializesConcurrentFirstUse
surfaced a second race it had masked: a slow guard reaches the hydrate mkdir only
after the winner already hydrated and released the lock, so its mkdir succeeds and it
runs the installer a second time ("hydrator ran 2 times under contention, want exactly 1").
Add double-checked locking: re-test the slot after acquiring the lock and run the
installer only if it is still missing or incomplete. Exactly one hydration happens
under contention, and redundant installer runs that widened the exec-time race window
are eliminated. Stressed 30x locally; guard/hook suite green.
Disclosure-Reviewed: reviewed — public-safe only, private facet kept out of this commit
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
Follow-up to #195. Once the ETXTBSY exec-retry landed, the sync PR's ubuntu job revealed a second race that the
Text file busyfailure had been masking:Root cause
The guard tests "is the slot missing?" (outer
if), then takes a clone-widemkdirlock to hydrate. Under contention a slow guard reaches themkdironly after the winner already hydrated and released the lock — so itsmkdirsucceeds too, on a stale outer test, and it runs the installer a second time. Not Linux-specific; timing-dependent (doesn't reliably reproduce on a fast Mac, surfaces under CI load).Fix
Double-checked locking: after acquiring the lock, re-test the slot and run the installer only if it is still missing/incomplete. Exactly one hydration happens under contention, and eliminating the redundant installer run also narrows the write-vs-exec window that #195 retries against.
Tests
Stressed
TestGuardAutoHydration*30× locally — all green; build + gofmt clean; release-note preflight passes. The existing test is unchanged; it correctly caught the race.Together with #195 this removes both concurrent-first-use failure modes at the source, so the projection sync stays green.