You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected the TCP socket opened by http.ListenAndServeTLS() to be closed before control was returned back to the caller.
What did you see instead?
The TCP socket was left in an open state.
If http.Server.ListenAndServeTLS() is called with either an invalid certificate or key, the function leaks the TCP socket that was opened for the server. This is because the method doesn't close the net.Listener before returning.
This is a side-effect of a difference in behaviors between http.Server.Serve() and http.Server.ServeTLS(). The non-TLS method defers a call to l.Close() to close the TCP socket before returning, the TLS version does not have this behavior implemented.
I'm not sure if the TLS method having different behavior is intentional, so I think there are two potential fixes:
Modify http.Server.ServeTLS() to defer a call to l.Close().
Avoid making behavioral changes to http.Server.ServeTLS() and instead do the defer in ListenAndServeTLS() where the TCP socket is created.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
I expected the TCP socket opened by
http.ListenAndServeTLS()
to be closed before control was returned back to the caller.What did you see instead?
The TCP socket was left in an open state.
If
http.Server.ListenAndServeTLS()
is called with either an invalid certificate or key, the function leaks the TCP socket that was opened for the server. This is because the method doesn't close thenet.Listener
before returning.This is a side-effect of a difference in behaviors between
http.Server.Serve()
andhttp.Server.ServeTLS()
. The non-TLS method defers a call tol.Close()
to close the TCP socket before returning, the TLS version does not have this behavior implemented.I'm not sure if the TLS method having different behavior is intentional, so I think there are two potential fixes:
http.Server.ServeTLS()
to defer a call tol.Close()
.http.Server.ServeTLS()
and instead do the defer inListenAndServeTLS()
where the TCP socket is created.The text was updated successfully, but these errors were encountered: