Skip to content

Commit addefca

Browse files
mzz2017DuckSoft
authored andcommitted
fix: a hidden problem that can lead to goroutine leaks
1 parent 04bf6df commit addefca

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

dispatcher/udp/udp.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ func (d *UDP) GetOrBuildUCPConn(laddr net.Addr, data []byte) (rc *net.UDPConn, e
127127
// auth every server
128128
server, content := d.Auth(buf, data, userContext)
129129
if server == nil {
130+
d.nm.Lock()
131+
// remove socketIdent to avoid goroutine leak
132+
if conn, ok = d.nm.Get(socketIdent); ok {
133+
select {
134+
case <-conn.Establishing:
135+
default:
136+
d.nm.Remove(socketIdent)
137+
}
138+
}
139+
d.nm.Unlock()
130140
return nil, AuthFailedErr
131141
}
132142

0 commit comments

Comments
 (0)