Skip to content

Commit

Permalink
Merge pull request #21 from Qv2ray/fix-memory-leak
Browse files Browse the repository at this point in the history
fix: a hidden problem that can lead to goroutine leaks
  • Loading branch information
DuckSoft authored May 9, 2021
2 parents 04bf6df + addefca commit 427f952
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 427f952

Please sign in to comment.