Skip to content

test(pool): idle-sweep tests wait for the sweep to finish before they end - #310

Merged
CMGS merged 1 commit into
mainfrom
fix/idle-sweep-test-race
Oct 4, 2026
Merged

CMGS merged 1 commit into
mainfrom
fix/idle-sweep-test-race

Conversation

@CMGS

@CMGS CMGS commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

A hibernate publishes HibernateSnap under m.mu, and only then commits claims.json and appends the usage event, outside the lock. Tests that ended on waitFor(hibernated(m) == 1) could therefore return while those writes were still running, racing the t.TempDir cleanup. CI on #309 hit this once: TempDir RemoveAll cleanup: unlinkat .../001: directory not empty in TestHeldConnectionBlocksIdleSweep.

sweepIdle(t, m) runs one sweep and waits for its goroutine to exit, and that goroutine exits after every write the sweep makes. All idleOnce call sites in the pool tests now use it. The tests that expect a hibernate assert it after the sweep has finished.

Test-only; no production change. go test -race ./pool, make go-lint (10 x 0 issues.), and asl on darwin and linux are green. The race needs CI-level CPU contention to show and did not reproduce locally (600 runs on mac, 400 in a 2-CPU linux container), so the fix rests on the ordering in hibernateLocked: commitTransition comes first, then recordHibernate, then disarmEgress and dropStale, all inside the sweep goroutine.

… end

A sweep publishes HibernateSnap under m.mu, then commits claims.json and
appends the usage event outside it, so a test that stopped at hibernated
== 1 could return while those writes ran and race the TempDir cleanup
(CI: "unlinkat ...: directory not empty"). sweepIdle runs one sweep and
waits for its goroutine to exit, which follows every write.
@CMGS
CMGS merged commit 085c8d3 into main Oct 4, 2026
1 check passed
@CMGS
CMGS deleted the fix/idle-sweep-test-race branch October 4, 2026 16:35
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