-
Notifications
You must be signed in to change notification settings - Fork 18k
net: Listener sometimes accepts connections after Close #13762
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
Comments
When Close is called on the listener, the goroutine blocked on Accept does not immediately error out. It's possible that new incoming connections will be accepted (at least on Linux). See: golang/go#13762 We can avoid this by making sure that the server is really closed (e.g. not accepting new connections) in close_test before trying to make a call.
This is a platform-indepedent issue and a duplicate of #10527. |
@mikioh I saw #10527, but I think this is a little different. #10527 is basically that the socket isn't closed since In this case, |
Thanks for the notice, hm, perhaps we need to dig accept4 more on both Linux and FreeBSD. |
To conclude, this is a duplicate of #10527. In general this may happen when the shared fdMutex in TCPListener is taken by acceptor goroutine prior to TCPListener.Close like the following:
See #10527 for further information. |
@mikioh Ah, I thought that perhaps Accept would check whether the socket was marked as Closed but that doesn't affect epoll from accepting new connections. It looks like the other issue has not had any progress since it was last marked as possibly for go 1.5. Can #10527 be prioritized for go 1.7? Thanks |
I've written a repro test here:
https://github.com/prashantv/listener-repro/blob/master/main.go
It basically does the following:
connectionsBeforeClose
connections to the listener (which should succeed)On the listener side, I expect to receive at most
connectionsBeforeClose
successful connections. Any extra connections causes therunTest
method to return an error.This works as expected on OSX, but on Linux, it seems to receive a successful connection after the listener has been closed.
Some things I noticed:
connectionsBeforeClose
is set to 0, then no unexpected connections are made after the listener is closedenableSleep
I would expect that a Listener will not accept any further socket attempts after
Close
has returned.The text was updated successfully, but these errors were encountered: