Release audio resources before reconnecting

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-09 14:50:01 -04:00
committed by Brandon McGinty
parent 25467405b8
commit d07d7342da
4 changed files with 27 additions and 1 deletions
+17
View File
@@ -81,6 +81,23 @@ type Barnard struct {
adminACL *gumble.ACL
}
// cleanupConnectionAudio releases connection-owned audio resources before a
// reconnect replaces them. It is intentionally idempotent for repeated
// disconnect notifications.
func (b *Barnard) cleanupConnectionAudio() {
if b.Stream != nil {
stream := b.Stream
b.Stream = nil
stream.Destroy()
}
b.FileStreamMutex.Lock()
if b.FileStream != nil {
_ = b.FileStream.Stop()
b.FileStream = nil
}
b.FileStreamMutex.Unlock()
}
func (b *Barnard) StopTransmission() {
if b.Tx {
b.Notify("micdown", "me", "")
+1
View File
@@ -168,6 +168,7 @@ func (b *Barnard) OnDisconnect(e *gumble.DisconnectEvent) {
reason = e.String
}
b.stopRecordingForDisconnect()
b.cleanupConnectionAudio()
// Tone test cleanup
if b.ToneTest {
+8
View File
@@ -53,6 +53,14 @@ func TestNotificationExpansionIsSinglePassAndNotifyDoesNotBlock(t *testing.T) {
}
}
// Regression: reconnect replaced Stream without destroying the old capture
// and renderer resources. Cleanup must be safe for repeated disconnects.
func TestCleanupConnectionAudioIsIdempotent(t *testing.T) {
b := &Barnard{}
b.cleanupConnectionAudio()
b.cleanupConnectionAudio()
}
func TestUserChangeNotification(t *testing.T) {
current := &gumble.Channel{ID: 1, Name: "Current"}
other := &gumble.Channel{ID: 2, Name: "Other"}
+1 -1
View File
@@ -92,7 +92,7 @@ Priority 1: transport, lifecycle, and correctness
Stop and join all audio stream goroutines before renderer shutdown; make
render reject work after shutdown without panicking.
11. Reconnect leaks the old audio stream
[x] 11. Reconnect leaks the old audio stream
File: client.go
OnDisconnect starts reconnecting but never destroys the existing Stream or
stops its file player/capture routine. connect creates a new Stream and