From addefca86530ed49965f4222b2ccf570d5fcf03f Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Sun, 9 May 2021 14:21:50 +0800 Subject: [PATCH] fix: a hidden problem that can lead to goroutine leaks --- dispatcher/udp/udp.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dispatcher/udp/udp.go b/dispatcher/udp/udp.go index 2eab3fc..a4df3a8 100644 --- a/dispatcher/udp/udp.go +++ b/dispatcher/udp/udp.go @@ -127,6 +127,16 @@ func (d *UDP) GetOrBuildUCPConn(laddr net.Addr, data []byte) (rc *net.UDPConn, e // auth every server server, content := d.Auth(buf, data, userContext) if server == nil { + d.nm.Lock() + // remove socketIdent to avoid goroutine leak + if conn, ok = d.nm.Get(socketIdent); ok { + select { + case <-conn.Establishing: + default: + d.nm.Remove(socketIdent) + } + } + d.nm.Unlock() return nil, AuthFailedErr }