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: document that File method is ONLY for passing to children #2458
Labels
Milestone
Comments
Comment 1 by sebastien.paolacci: Kind of duplicate of issue #1692 "SO_REUSEADDDR vs UDP vs timeouts": same root cause in both cases. |
Passing a non-blocking fd only works if you are giving the fd to a program that will do non-blocking I/O. A common case is to accept the network connection and then use that fd as stdin, stdout, and stderr when running an ordinary program. Those programs typically do not expect non-blocking i/o on those fds and will behave incorrectly. It sounds like you are passing the fd to a program that is going to use non-blocking i/o itself, so it is going to put the fd back in non-blocking mode no matter what you pass it. The usual convention is that at program startup a preopened fd is in blocking mode. For example, here is a good way to kill your shell: run a program that leaves the tty in non-blocking mode when it exits: package main import "syscall" func main() { syscall.SetNonblock(0, true) } |
As another data point, we did this: file, err := c.File() fd := file.Fd() syscall.SetsockoptInet4Addr(fd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, addr) which caused all kinds of interesting issues. On Close the UDP socket we broke by calling File() would sometimes do one of the following: - return "address family not supported by protocol" from Read - return "bad file descriptor" from Read - return n = 0 and a nil error Hopefully others might find this and avoid this problem. |
Fixed by https://golang.org/cl/6869054 |
This issue was closed by revision 5416e6e. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by sebastien.paolacci:
Attachments:
The text was updated successfully, but these errors were encountered: