Skip to content

flaky tests: fix supervisor and relay manager data races, gate package on -race - #185

Merged
shawnburke merged 2 commits into
mainfrom
shawn/snykbroker-test-races
Nov 9, 2026
Merged

shawnburke merged 2 commits into
mainfrom
shawn/snykbroker-test-races

Conversation

@shawnburke

Copy link
Copy Markdown
Collaborator

Summary

go test -race ./server/snykbroker/ failed on main (7 tests, 31 race reports). CI didn't catch it because make test-race only covered the reflector tests in this package. Three races, all between the goroutine that runs the broker and whoever stops it:

  • Supervisor stop vs start (supervisor.go): the stop func read cmd.Process while cmd.Start() wrote it on another goroutine. The process handle is now published under a lock. A stop that arrives before the process exists kills it as soon as it starts, instead of waiting for it to exit on its own.
  • relayInstanceManager.supervisor: written by Start's goroutine and read/cleared by Close with no synchronisation. It's now guarded, with a currentSupervisor() accessor that the tests use too.
  • Start's return value: Start returned the shared err after its wait timed out, while the goroutine could still be writing it (from supervisor.Start or supervisor.Wait). The goroutine now publishes the result through a mutex-guarded startResult, and Start returns the same value as before.

With those fixed the whole package passes -race. ./server/snykbroker/... moves into RACE_CLEAN_PKGS and the reflector-only -run gating is removed.

Still not race-clean, unchanged here: server, server/handler, server/http (the handler manager and the fx server stack).

Test plan

  • go test -race -count=5 ./server/snykbroker/...: clean, no race reports
  • go test -race over the full RACE_CLEAN_PKGS list: all pass
  • go test ./server/snykbroker/ without -race: passes

🤖 Generated with Claude Code

shawnburke and others added 2 commits November 10, 2026 08:18
… on -race

Three races, all between the goroutine that runs the broker and whoever
stops it:

- Supervisor: the stop func read cmd.Process while cmd.Start wrote it. The
  process handle is now published under a lock, and a stop that lands before
  the process exists kills it as soon as it starts.
- relayInstanceManager.supervisor was written by Start's goroutine and
  read/cleared by Close with no synchronisation; it is now guarded.
- Start returned the shared err after its wait timed out while the goroutine
  could still be writing it; the goroutine now publishes through a
  mutex-guarded result.

With those fixed the whole package passes -race, so it joins
RACE_CLEAN_PKGS and the reflector-only test gating goes away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was a local untracked file swept up by the previous commit; with no
golden file beside it, TestRenderGolden fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shawnburke
shawnburke enabled auto-merge (squash) November 9, 2026 21:27
@shawnburke shawnburke changed the title snykbroker: fix supervisor and relay manager data races, gate package on -race flaky tests: fix supervisor and relay manager data races, gate package on -race Nov 9, 2026
@shawnburke
shawnburke merged commit 490e09e into main Nov 9, 2026
29 checks passed
@shawnburke
shawnburke deleted the shawn/snykbroker-test-races branch November 9, 2026 21:44
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.

2 participants