Skip to content

Commit

Permalink
Update SocketReader::ReadSome SocketError when socket closed
Browse files Browse the repository at this point in the history
Update SocketInitiatorThread::ReadSome SocketError when socket closed

If 0 bytes are read it means the socket has been shutdown not reset. Had this issue in a production system reporting "Connection reset by peer" (the error message for SocketError.SocketReset), but using wireshark no RST packet was seen.
However we did see the FIN and FIN,ACK packets which means the socket was being deliberately shutdown. Turned out the venue had a maintenance job that shutdown the network connections.

Tldr; Setting to SocketError.Shutdown is the correct message for this scenario.
  • Loading branch information
oclancy authored and Oliver Clancy committed Jun 22, 2023
1 parent c4e8171 commit 8435474
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion QuickFIXn/SocketInitiatorThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected int ReadSome(byte[] buffer, int timeoutMilliseconds)

int bytesRead = stream_.EndRead(request);
if (0 == bytesRead)
throw new SocketException(System.Convert.ToInt32(SocketError.ConnectionReset));
throw new SocketException(System.Convert.ToInt32(SocketError.Shutdown));

return bytesRead;
}
Expand Down
2 changes: 1 addition & 1 deletion QuickFIXn/SocketReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected virtual int ReadSome(byte[] buffer, int timeoutMilliseconds)

int bytesRead = stream_.EndRead(request);
if (0 == bytesRead)
throw new SocketException(System.Convert.ToInt32(SocketError.ConnectionReset));
throw new SocketException(System.Convert.ToInt32(SocketError.Shutdown));

return bytesRead;
}
Expand Down

0 comments on commit 8435474

Please sign in to comment.