With the defers stacked like this, kind of the only sensible way, when you try to close the listener gets closed first, and you can hang indefinitely.
I've been able to work around the issue by building code that sets timeouts for the listener to close and if it fails, starts closing stuff from the bottom up, but it's much more difficult than being able to set a timeout for the listener to close down.
Go version
x/crypto v0.27.0
Output of
go env
in your module/workspace:What did you do?
Connect via SSH and set up remote forwarding of a TCP port or Unix socket (both exhibit the problem) via a call to
Listen()
.Break the networking: unplug Ethernet cable, disable WiFi, etc.
Close the Listener.
What did you see happen?
Closing the Listener hangs indefinitely, until the TCP socket times out, which could be hours or days.
What did you expect to see?
Closing the Listener times out with some reasonable timeframe, or accepts a timeout (e.g. via a `Context).
Typical use patterns would be:
With the
defer
s stacked like this, kind of the only sensible way, when you try to close the listener gets closed first, and you can hang indefinitely.I've been able to work around the issue by building code that sets timeouts for the listener to close and if it fails, starts closing stuff from the bottom up, but it's much more difficult than being able to set a timeout for the listener to close down.