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: TCPConn.CloseRead() will not cause the net.TCPConn.Read() return on windows but it can cause return on linux #41002
Comments
What’s is the value of n returned on windows? |
@davecheney |
what is the value of n on the linux system? |
@davecheney on linux,when call closeread,the read will return with an error |
Read returns two values, a count of the number of bytes and an error. You’ve identified that the error is not nil, what was the count of the number of bytes read? |
@davecheney the count of the number is 0,the client is sleep on |
Thank you for explaining. I’m trying to understand the Issue you are reporting. It is not that the code panics under linux and not under windows because the panic is in your code, not go. The difference appears to be that under linux when you call CloseRead in another goroutine the Goroutine waiting in Read receives 3, nil on windows and 0, (some non nil error) on linux. Is that a correct summary? |
@davecheney the summary is:
run the code by your self or show it to other developers,they will know what happened |
I’m sorry I don’t have access to a windows computer. |
@chenjie199234 can you please try this self contained program
|
@davecheney on windows return this:between the first line output and second line output,the program will block 1 minute |
@chenjie199234 thank you for confirming. I'm going to hand this over to the windows experts now. /cc @alexbrainman |
Thank you @davecheney for helping here. I can reproduce @chenjie199234 result on Windows, but I am not convinced there is a problem here. We do client Read in that order. It appears that CloseRead behaves differently on Linux and Windows. On Linux it makes Read return EOF, and (I assume) makes Write fail. On Windows it makes Read return sent bytes, and (I assume) makes Write succeed. I say either scenario is fine. There is a race here between Read and CloseRead, and result here depends on network stack implementation. In my view, CloseRead cannot be used for anything useful. Only Close and CloseWrite are useful. Both ends of the connection should keep reading from the connection until EOF, if you do not want to loose some data. Alex |
same code has different performace on windows and linux
start the server first and then start the client
on linux:the server will panic
on windows:the server will not panic
golang version 1.14.4
server
client
The text was updated successfully, but these errors were encountered: