Skip to content

fix: eliminate ARM64 data race on Server.session pointer#328

Merged
tomasz-tomczyk merged 2 commits intomainfrom
fix/arm64-session-race
Apr 21, 2026
Merged

fix: eliminate ARM64 data race on Server.session pointer#328
tomasz-tomczyk merged 2 commits intomainfrom
fix/arm64-session-race

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

  • Replace session *Session + ready atomic.Bool with atomic.Pointer[Session] to fix a data race on ARM64 (Apple Silicon)
  • On weakly-ordered architectures, atomic.Bool.Store doesn't order the preceding pointer write, so a handler goroutine could see ready=true but read a stale nil s.session
  • All readiness checks now derive from s.session.Load() != nil

Test plan

  • go vet ./... clean
  • go test -race -count=1 ./... passes
  • Reviewed by Go expert agent — approved

🤖 Generated with Claude Code

tomasz-tomczyk and others added 2 commits April 21, 2026 22:14
Replace the `session *Session` + `ready atomic.Bool` two-field pattern
with `session atomic.Pointer[Session]`. The old pattern had a data race:
SetSession wrote the pointer without synchronization, then stored true
to the atomic bool. On weakly-ordered architectures (ARM64/Apple Silicon),
a handler goroutine could observe ready=true but read a stale nil session
pointer, since atomic.Bool.Store only orders the boolean itself.

With atomic.Pointer, the session store is a single atomic operation.
Readiness is derived from the pointer being non-nil, eliminating the
race entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Load session once instead of twice for consistency with other handlers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tomasz-tomczyk tomasz-tomczyk force-pushed the fix/arm64-session-race branch from aab4c0c to ac1b462 Compare April 21, 2026 21:14
@tomasz-tomczyk tomasz-tomczyk merged commit 2a62362 into main Apr 21, 2026
4 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix/arm64-session-race branch April 21, 2026 21:24
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