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 gbirchmeier committed Jan 24, 2024
1 parent a6efe80 commit 84e06a2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 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 @@ -94,7 +94,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
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ What's New
* #764 - fix positive UTC offset parsing in DateTimeConverter (Rob-Hague)
* #766 - use ordinal string operations (Rob-Hague)
* #767 - Avoid string conversions in FieldMap.Get{FieldType} where possible (Rob-Hague)

* #785 - use correct SocketError "Shutdown" code when socket is deliberately shutdown (oclancy)

### v1.11.2:
* same as v1.11.1, but I fixed the readme in the pushed nuget packages
Expand Down

0 comments on commit 84e06a2

Please sign in to comment.