Skip to content

fix(pools): read a pool's capabilities under the lock in Supports - #134

Merged
reachjalil merged 1 commit into
pre-releasefrom
fix/pools-entry-read-race
Nov 20, 2026
Merged

reachjalil merged 1 commit into
pre-releasefrom
fix/pools-entry-read-race

Conversation

@reachjalil

Copy link
Copy Markdown
Member

What

Manager.Supports looked the pool entry up under m.mu.RLock(), then read e.caps after releasing it. Refresh's probe goroutines write e.caps (and capacity/health fields) under m.mu.Lock(), so the two raced. It showed up intermittently in go test -race -tags experimental_adapters ./internal/loadsim/ under load (TestKeptSandboxesHibernateAndWake, TestDisableAPoolLive, via Scheduler.ReleasesSlot).

Supports now copies the adapter and capabilities before unlocking; the fallback Capabilities call still runs unlocked. The other Manager methods already read entry fields under the lock. e.adapter is set only when an entry is created and never mutated, so Refresh's unlocked read of it is safe.

Proof

  • New TestSupportsDuringRefresh runs Refresh and Supports concurrently: it reports DATA RACE and fails without the fix, and passes with it (-race -count=20).
  • go test -race -count=3 -tags experimental_adapters ./internal/loadsim/ passes.
  • make verify passes (includes internal/server acceptance tests).
  • Not run: make test-postgres (no change to internal/store or internal/server).

🤖 Generated with Claude Code

Supports looked the entry up under the read lock, then read e.caps after
releasing it, while Refresh's probe goroutines rewrite caps under the
write lock. Copy the adapter and capabilities before unlocking. The other
Manager methods already read entry fields under the lock; e.adapter is
set only when an entry is created, so Refresh's unlocked read of it is safe.

TestSupportsDuringRefresh fails under -race without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jalil <reachjalil@gmail.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI passed at 63f637d.

@reachjalil
reachjalil merged commit 7a5e425 into pre-release Nov 20, 2026
22 checks passed
@reachjalil
reachjalil deleted the fix/pools-entry-read-race branch November 20, 2026 19:37
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