From 5eacbb7239c7d1ab5ad09814ef4adcc091e9ce78 Mon Sep 17 00:00:00 2001 From: Laurence Date: Fri, 13 Mar 2026 16:43:16 +0000 Subject: [PATCH] fix(proxy): prevent deleting wrong tunnel in defer cleanup Add pointer check before delete to handle race where UpdateLocalSNIs removes our tunnel and a new one is created for the same hostname. --- proxy/proxy.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 4d814e9..153dcb6 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -608,7 +608,9 @@ func (p *SNIProxy) handleConnection(clientConn net.Conn) { tunnel.count-- if tunnel.count == 0 { tunnel.cancel() - delete(p.activeTunnels, hostname) + if p.activeTunnels[hostname] == tunnel { + delete(p.activeTunnels, hostname) + } } p.activeTunnelsLock.Unlock() }()