From 0ecdbf988fa916d4a0edc53bec941742de52cf4f Mon Sep 17 00:00:00 2001 From: "Brandon McGinty (deepseek)" Date: Sat, 8 Aug 2026 22:37:53 -0400 Subject: [PATCH] fix: start UDP socket before connection handshake to avoid race MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CryptSetup can arrive during the initial sync (before handleServerSync completes). Previously startUDP() was called after the sync finished, so if CryptSetup arrived first, crypto was initialized but the UDP socket didn't exist yet — causing a permanent fallback to TCP. Move startUDP() to immediately after writing the Version/Authenticate packets and before waiting for the sync to complete. The UDP socket is now ready when CryptSetup arrives. --- gumble/gumble/client.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gumble/gumble/client.go b/gumble/gumble/client.go index 749e272..eeef14a 100644 --- a/gumble/gumble/client.go +++ b/gumble/gumble/client.go @@ -140,6 +140,14 @@ func DialWithDialer(dialer *net.Dialer, config *Config, tlsConfig *tls.Config) ( client.Conn.WriteProto(&versionPacket) client.Conn.WriteProto(&authenticationPacket) + // Start UDP transport immediately so it's ready when CryptSetup + // arrives during the sync handshake. + if err := client.startUDP(); err != nil { + log.Warn("UDP setup failed, audio will use TCP tunnel: %v", err) + } else if client.udpConn != nil { + log.Info("UDP socket opened to %s, waiting for CryptSetup", client.udpConn.RemoteAddr()) + } + go client.pingRoutine() var timeout <-chan time.Time @@ -171,14 +179,6 @@ func DialWithDialer(dialer *net.Dialer, config *Config, tlsConfig *tls.Config) ( return nil, err } - // Start UDP transport for lower-latency audio. This is best-effort; - // if UDP fails, audio falls back to TCP tunneling. - if err := client.startUDP(); err != nil { - log.Warn("UDP setup failed, audio will use TCP tunnel: %v", err) - } else if client.udpConn != nil { - log.Info("UDP socket opened to %s, waiting for CryptSetup", client.udpConn.RemoteAddr()) - } - return client, nil } }