Fix ephemeral port leak.

Fix a bug where udp.(*endpoint).Disconnect [accessible in gVisor via
epsocket.(*SocketOperations).Connect with AF_UNSPEC] would leak a port
reservation if the socket/endpoint had an ephemeral port assigned to it.

glibc's getaddrinfo uses connect with AF_UNSPEC, causing each call of
getaddrinfo to leak a port. Call getaddrinfo too many times and you run out of
ports (shows up as connect returning EAGAIN and getaddrinfo returning
EAI_NONAME "Name or service not known").

PiperOrigin-RevId: 268071160
This commit is contained in:
Ian Gudger
2019-09-09 14:02:00 -07:00
committed by gVisor bot
parent 3733b9b893
commit 9dfcd8b09f
+4
View File
@@ -747,6 +747,10 @@ func (e *endpoint) Disconnect() *tcpip.Error {
}
e.state = StateBound
} else {
if e.id.LocalPort != 0 {
// Release the ephemeral port.
e.stack.ReleasePort(e.effectiveNetProtos, ProtocolNumber, e.id.LocalAddress, e.id.LocalPort)
}
e.state = StateInitial
}