Skip to content

fix: guard gateway & voice shared state against data races - #559

Open
sealbro wants to merge 1 commit into
disgoorg:masterfrom
sealbro:fix/gateway-data-races
Open

fix: guard gateway & voice shared state against data races#559
sealbro wants to merge 1 commit into
disgoorg:masterfrom
sealbro:fix/gateway-data-races

Conversation

@sealbro

@sealbro sealbro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

fix: guard gateway & voice shared state against data races

Summary

Mutable fields on gatewayImpl (HTTP & voice) and the audio sender/receiver were read/written from multiple goroutines (listen loop, heartbeat, and caller Open/Close/Latency) without synchronization. This adds mutexes and accessor helpers so all shared state is accessed safely, fixing the races flagged under -race.

Changes

  • gateway/gateway.goheartbeatMu guards heartbeatCancel + heartbeat timestamps; seqMu guards LastSequenceReceived. setLastSequenceReceived now stores a copy, so the pointer no longer aliases the listen loop's message struct.
  • voice/gateway.go — same heartbeat/seq guarding, plus lastNonce, ssrc, and seq accessors.
  • voice/audio_sender.go / audio_receiver.gosync.Mutex guards cancelFunc, now created in Open() before the goroutine starts and nil-checked in Close() (fixes a race + possible nil deref).

Testing

  • go test --race -cover ./...
  • go build ./...
  • golangci-lint run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant