-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: shutdown on http.Server serving through net.Listener closes listener twice #24803
Comments
The // Close closes the listener.
// Any blocked Accept operations will be unblocked and return errors.
Close() error Should a Listener user be allowed to call Close more than once, and expect the subsequent calls to be no-ops? |
The first Line 2624 in cf77603
The second is from: Line 2758 in cf77603
The |
@gregory-m |
@pam4 right. Here our options:
|
I've been in the situation of writing code similar to
But we cannot rely on
The second place is after |
cc @bradfitz. We need decision here. |
This is also related: #20705 // Closer is the interface that wraps the basic Close method.
//
// The behavior of Close after the first call is undefined.
// Specific implementations may document their own behavior.
type Closer interface {
Close() error
} |
Implementations of net.Listener should be tolerant of multiple Close calls, but users of net.Listeners (net/http) should also try to only call them once, in case implementations aren't tolerant. What about https://go-review.googlesource.com/#/c/go/+/106715? Does that work for y'all? |
Change https://golang.org/cl/106715 mentions this issue: |
Ok, thanks for the clarification, then you advise to play it safe on both sides. I also noticed that this CL would make 106657 superfluous since now |
Well, at least its test is still valid. |
This change fixes a non-critical panic which was occurring with go1.10. In some situations, Close would get called multiple times on the listener when exiting the trace-agent. For details, see golang/go#24803
* pkg/trace/api: ensure listener gets closed only once This change fixes a non-critical panic which was occurring with go1.10. In some situations, Close would get called multiple times on the listener when exiting the trace-agent. For details, see golang/go#24803
* pkg/trace/api: ensure listener gets closed only once This change fixes a non-critical panic which was occurring with go1.10. In some situations, Close would get called multiple times on the listener when exiting the trace-agent. For details, see golang/go#24803
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.10.1 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
When I run the following code, the listener is closed twice:
The problem appears to be in
http/server.go
, whereShutdown
will callsrv.closeListenersLocked
which closes our listener. But asServe
exits, the first row in that function defines adefer l.Close()
that closes the listener as well! I think the latter should go, if I understand it correctly.What did you expect to see?
I expected the listener to be closed only once, this is causing double closes on underlying structures in our production.
What did you see instead?
You will notice that
Close
is called twice.The text was updated successfully, but these errors were encountered: