Skip to content

fix(boatstack): concurrent first use hydrates the shared runtime exactly once - #198

Merged
bigboateng merged 1 commit into
mainfrom
fix/guard-hydrate-double-check
Jul 26, 2026
Merged

fix(boatstack): concurrent first use hydrates the shared runtime exactly once#198
bigboateng merged 1 commit into
mainfrom
fix/guard-hydrate-double-check

Conversation

@bigboateng

Copy link
Copy Markdown
Contributor

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 busy failure had been masking:

--- FAIL: TestGuardAutoHydrationSerializesConcurrentFirstUse
  hooks_hydrate_test.go:218: hydrator ran 2 times under contention, want exactly 1

Root cause

The guard tests "is the slot missing?" (outer if), then takes a clone-wide mkdir lock to hydrate. Under contention a slow guard reaches the mkdir only after the winner already hydrated and released the lock — so its mkdir succeeds 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.

…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
@bigboateng
bigboateng merged commit f671638 into main Jul 26, 2026
11 checks passed
@bigboateng
bigboateng deleted the fix/guard-hydrate-double-check branch July 26, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant