-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
StreamReader.Read does not throw any exceptions when TCP/IP connection lost on Linux #42232
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/ncl |
This is a general TCP issue -- if you have no outstanding sends for the other side to ACK, and the other side isn't sending you anything, then the socket has no way of discovering a network cable unplug. You can set SocketOptionName.KeepAlive to true on your socket, which will cause the TCP stack to send occasional pings to check if an idle connection is still alive. By default this only happens after 2hr, so it may not react quick enough for you -- there are OS settings to adjust it to check sooner. |
Thank you everyone. I found that Read function returns 0 when disconnection happened. It is good enough for my purpose because my task is for communication between two embedded systems only, and it is ok as long as my product works. When it detect disconnection, they just start over connection. I would try SocketOptionName.KeepAlive if my workaround does not work. |
StreamReader.Read does not throw any exception when TCP/IP connection lost on Ubuntu 20.04.
General
When you use System.Net.Sockets.TcpListener and StreamReader.Read, the Read method generates System.IO.IOException on Windows 10, when network disconnection occurs. The error message is "Unable to read data from the transport connection: A socket operation was attempted to an unreachable network..". I can implement some error handlers with this exception.
However no exceptions observed on Ubuntu 20.04. The version of dotnet core is 3.1.300. I'm generating the disconnection error removing a network cable physically.
The text was updated successfully, but these errors were encountered: