Skip to content

Commit

Permalink
fix: a hidden problem that can lead to goroutine leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 authored and DuckSoft committed May 9, 2021
1 parent 04bf6df commit addefca
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dispatcher/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit addefca

Please sign in to comment.