Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Commit

Permalink
netstack: release port inline for listening sockets only.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 229243918
  • Loading branch information
zhaozhongn authored and shentubot committed Jan 14, 2019
1 parent b4af50d commit 47d86e3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tcpip/transport/tcp/endpoint.go
Expand Up @@ -410,18 +410,18 @@ func (e *endpoint) Close() {

e.mu.Lock()

// We always release ports inline so that they are immediately available
// for reuse after Close() is called. If also registered, it means this
// is a listening socket, so we must unregister as well otherwise the
// next user would fail in Listen() when trying to register.
if e.isPortReserved {
e.stack.ReleasePort(e.effectiveNetProtos, ProtocolNumber, e.id.LocalAddress, e.id.LocalPort)
e.isPortReserved = false

// For listening sockets, we always release ports inline so that they
// are immediately available for reuse after Close() is called. If also
// registered, we unregister as well otherwise the next user would fail
// in Listen() when trying to register.
if e.state == stateListen && e.isPortReserved {
if e.isRegistered {
e.stack.UnregisterTransportEndpoint(e.boundNICID, e.effectiveNetProtos, ProtocolNumber, e.id, e)
e.isRegistered = false
}

e.stack.ReleasePort(e.effectiveNetProtos, ProtocolNumber, e.id.LocalAddress, e.id.LocalPort)
e.isPortReserved = false
}

// Either perform the local cleanup or kick the worker to make sure it
Expand Down Expand Up @@ -457,6 +457,12 @@ func (e *endpoint) cleanupLocked() {

if e.isRegistered {
e.stack.UnregisterTransportEndpoint(e.boundNICID, e.effectiveNetProtos, ProtocolNumber, e.id, e)
e.isRegistered = false
}

if e.isPortReserved {
e.stack.ReleasePort(e.effectiveNetProtos, ProtocolNumber, e.id.LocalAddress, e.id.LocalPort)
e.isPortReserved = false
}

e.route.Release()
Expand Down

0 comments on commit 47d86e3

Please sign in to comment.