From 0c5c59cf00156a95f3c68f31a21bac438916331c Mon Sep 17 00:00:00 2001 From: Owen Schwartz Date: Mon, 27 Jan 2025 21:28:22 -0500 Subject: [PATCH] Fix removing udp sockets --- proxy/manager.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/proxy/manager.go b/proxy/manager.go index 92218fa..b6c521b 100644 --- a/proxy/manager.go +++ b/proxy/manager.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "net" + "strings" "sync" "time" @@ -279,6 +280,22 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) { if !pm.running { return } + + // Check for connection closed conditions + if err == io.EOF || strings.Contains(err.Error(), "use of closed network connection") { + logger.Info("UDP connection closed, stopping proxy handler") + + // Clean up existing client connections + clientsMutex.Lock() + for _, targetConn := range clientConns { + targetConn.Close() + } + clientConns = nil + clientsMutex.Unlock() + + return + } + logger.Error("Error reading UDP packet: %v", err) continue }