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

Comments

Projects
None yet
7 participants
@adg
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented May 30, 2011

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

This comment has been minimized.

Copy link
Contributor

commented May 31, 2011

Comment 2:

Yes
@gopherbot

This comment has been minimized.

Copy link

commented Aug 30, 2011

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

This comment has been minimized.

Copy link
Member

commented Aug 30, 2011

Comment 5:

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Dec 9, 2011

Comment 8:

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

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 12, 2011

Comment 9:

Labels changed: added priority-go1.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Jan 13, 2012

Comment 10:

Owner changed to builder@golang.org.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Feb 12, 2012

Comment 12:

Owner changed to @rsc.

Status changed to Started.

@rsc

This comment has been minimized.

Copy link
Contributor

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

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.