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
+9 -9
View File
@@ -253,7 +253,7 @@ func (c *Config) findUser(address string, username string) *eUser {
func (c *Config) ToggleMute(u *gumble.User) {
j := c.findUser(u.GetClient().Config.Address, u.Name)
j.LocallyMuted = !j.LocallyMuted
u.LocallyMuted = j.LocallyMuted
u.SetLocallyMuted(j.LocallyMuted)
c.SaveConfig()
}
@@ -329,11 +329,11 @@ func (c *Config) UpdateUser(u *gumble.User) {
uc = u.GetClient()
if uc != nil {
j = c.findUser(uc.Config.Address, u.Name)
u.Boost = j.Boost
u.Volume = j.Volume
u.LocallyMuted = j.LocallyMuted // Update LocallyMuted state from config
if u.Boost < 1 {
u.Boost = 1
u.SetBoost(j.Boost)
u.SetVolume(j.Volume)
u.SetLocallyMuted(j.LocallyMuted) // Update LocallyMuted state from config
if u.Boost() < 1 {
u.SetBoost(1)
}
}
}
@@ -341,9 +341,9 @@ func (c *Config) UpdateUser(u *gumble.User) {
func (c *Config) UpdateConfig(u *gumble.User) {
var j *eUser
j = c.findUser(u.GetClient().Config.Address, u.Name)
j.Boost = u.Boost
j.Volume = u.Volume
j.LocallyMuted = u.LocallyMuted // Save LocallyMuted state to config
j.Boost = u.Boost()
j.Volume = u.Volume()
j.LocallyMuted = u.LocallyMuted() // Save LocallyMuted state to config
}
func NewConfig(fn *string) *Config {