-
Notifications
You must be signed in to change notification settings - Fork 18k
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: reading a connectionless datagram socket after a CloseRead still blocks indefinitely #15250
Comments
Which operating system/version are you running? |
Go 1.6 on Ubuntu. |
CloseRead and CloseWrite call shutdown system call internally. I guess that the functionality is just for full-duplex connection-oriented sockets such as "tcp" or "unix". I suspect that Linux kernel doesn't support shutdown on connectionless datagram sockets such as "udp" or "unixgram". |
To be clear, everything works fine with |
Good to know, Linux always keeps moving forward, thanks. Though, I'm not sure what's the best way to make consistent behavior across all supported platforms. |
I am not very familiar with the internals of the I haven't looked on implementing it on the other platforms but some questions need to be answered first:
|
Before having a look at your code, can you please make sure your proposal about the following:
|
Sorry I haven't been clear enough: I am only speaking of datagrams on Unix sockets and not UDP. Currently the *UnixConn.CloseRead method already exists. When it is used on an "unixgram" socket, writes to the Unix socket fail but it is still possible to read the packets in the buffer of the socket. And I don't want to change any of these behaviors. So to answer your questions:
I don't want to change the current behavior.
I don't want to change the current behavior.
It represents the end of incoming data since the socket cannot be written anymore. |
I'm still confused. When I run https://github.com/mikioh/-stdyng/tree/master/cmd/ugrmshtdwn, which is based on your snippet, I have a few different results like the following:
Probably the results depend on each implementation, especially the plumbing between socket layer that manages the general connection-oriented/connectionless state, and transport protocol layer that is the real conveyer. I suppose that if you really want to modify the behavior of Read, you also need to modify the behavior of CloseRead for avoiding confusion and incnsistency. I'm still not sure what we should do. At least we need to clarify three things before moving forward; 1) the desired behavior of CloseRead on unixgram socket, 2) the desired behavior of Read on cant-read-anymore unixgram socket, 3) whether we should use io.EOF as a cannot-read-anymore signal on unixgram socket, and which method should do. PS: Please change the description appropriately, like "proposal: net: blah blah". |
Thanks that's very interesting. I wrongly assumed that shutdown was working with unxigrams but after having a look at the doc of I think it is a very bad idea to try to unify an unspecified behavior on multiple platforms. So I am closing this issue. Thanks for your patience! |
I was trying to cleanly close a Unix socket (i.e. stop receiving traffic, read all the socket buffer and then close the socket) but found it a bit cumbersome.
The issue is that the following code blocks indefinitely:
To read all the socket buffer without blocking indefinitely you have to either:
conn.Close()
after a timeout to unblockconn.Read()
conn.File()
andsyscall.SetNonblock()
to read the connection buffer in a non-blocking wayI don't like
1.
since it would make my tests slow or flaky.2.
works well but it makes the code more complex.Since after a
CloseRead()
, a socket cannot receive more data I think it would make sense thatRead
returns anio.EOF
when it reaches the end of the connection buffer.The text was updated successfully, but these errors were encountered: