fix: add synchronization to User audio fields to prevent data races

User.AudioSource, Boost, Volume, and LocallyMuted were accessed from
both the OnAudioStream audio goroutine and the UI goroutine without
synchronization, a data race under the Go memory model.

Replace direct field access with thread-safe getter/setter methods
protected by a per-user mutex:
- SetAudioSource/GetAudioSource for the OpenAL source pointer
- SetBoost/Boost for the audio boost multiplier
- SetVolume/Volume for the volume level
- SetLocallyMuted/LocallyMuted for the local mute state

Update all call sites across config/, barnard.go, client.go,
ui_tree.go, and stream.go.
This commit is contained in:
Brandon McGinty (deepseek)
2026-08-08 20:58:53 -04:00
committed by Brandon McGinty
parent 1bdd7ac52e
commit 9dd0137975
6 changed files with 112 additions and 51 deletions
+3 -3
View File
@@ -179,11 +179,11 @@ func (b *Barnard) OnUserChange(e *gumble.UserChangeEvent) {
// If the channel is muted, ensure the user is muted
if b.MutedChannels[e.User.Channel.ID] {
// Only mute if not already muted
if !e.User.LocallyMuted {
if !e.User.LocallyMuted() {
b.UserConfig.ToggleMute(e.User)
}
if e.User.AudioSource != nil {
e.User.AudioSource.SetGain(0)
if au := e.User.AudioSource(); au != nil {
au.SetGain(0)
}
}
}