Skip to content
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: Listener should return errors to pending Accepts when it is Closed #1898

Closed
adg opened this issue May 30, 2011 · 11 comments
Closed

net: Listener should return errors to pending Accepts when it is Closed #1898

adg opened this issue May 30, 2011 · 11 comments
Milestone

Comments

@adg
Copy link
Contributor

adg commented May 30, 2011

For the net.Listener L some goroutines may be blocking on call to L.Accept(). If another
goroutine calls L.Close(), should those other goroutines receive an error?

The code below tests the behavior. Currently the Accept will block forever, and the
message "Shutting down" will never be seen.

--

package main

import (
    "log"
    "net"
    "time"
)

func main() {
    l, err := net.Listen("tcp", "localhost:2000")
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Listening")
    go func() {
        time.Sleep(2e9)
        log.Println("Closing")
        l.Close()
    }()
    _, err = l.Accept()
    log.Println("Shutting down:", err)
}
@kylelemons
Copy link
Contributor

Comment 1:

I solve this by making a dummy Dial() on the listener port and ignoring the error
return.  It's not ideal, but it works.  Returning an error from all active Accepts()
would be a much cleaner solution if it can be done.

@rsc
Copy link
Contributor

rsc commented May 31, 2011

Comment 2:

Yes

@gopherbot
Copy link

Comment 4 by grijalva:

I've run into this same issue.  Does anybody have any guidance for where one might start
solving the root problem?  I don't know the innards of the net library very well.

@bradfitz
Copy link
Contributor

Comment 5:

Fix is in progress here:
http://golang.org/cl/4953047/

@bradfitz
Copy link
Contributor

bradfitz commented Nov 7, 2011

Comment 6:

Is this fixed now?
On Linux at least I now get:
2011/11/07 13:37:41 Listening
2011/11/07 13:37:43 Closing
2011/11/07 13:37:43 Shutting down: invalid argument
... but I don't remember seeing the change that fixed this.
Is it guaranteed that the return value in this case is EINVAL?  Should this be
documented / tested somewhere?

@mikioh
Copy link
Contributor

mikioh commented Nov 7, 2011

Comment 7:

> Is this fixed now?
No, at least on darwin and freebsd,
2011/11/08 07:39:26 Listening
2011/11/08 07:39:28 Closing
and if we poke at this service by telnet localhost 2000,
we eventually get:
2011/11/08 07:40:35 Shutting down: invalid argument

@rsc
Copy link
Contributor

rsc commented Dec 9, 2011

Comment 8:

Labels changed: added priority-later, removed priority-medium.

@rsc
Copy link
Contributor

rsc commented Dec 12, 2011

Comment 9:

Labels changed: added priority-go1.

@robpike
Copy link
Contributor

robpike commented Jan 13, 2012

Comment 10:

Owner changed to builder@golang.org.

@rsc
Copy link
Contributor

rsc commented Feb 12, 2012

Comment 12:

Owner changed to @rsc.

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Feb 14, 2012

Comment 13:

This issue was closed by revision 5e4e3d8.

Status changed to Fixed.

@adg adg added fixed labels Feb 14, 2012
@adg adg assigned rsc Feb 14, 2012
@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants