Skip to content

Commit

Permalink
Merge pull request #881 from AArnott/logMoreOnDisconnect
Browse files Browse the repository at this point in the history
Retain the exception that leads to exiting the read loop
  • Loading branch information
AArnott authored Jan 11, 2023
2 parents b9ef10b + 0c25437 commit 9bd73af
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/StreamJsonRpc/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,7 @@ private async Task ReadAndHandleRequestsAsync()
try
{
this.TraceSource.TraceEvent(TraceEventType.Information, (int)TraceEvents.ListeningStarted, "Listening started.");
Exception? loopBreakingException = null;

while (!this.IsDisposed && !this.DisconnectedToken.IsCancellationRequested)
{
Expand All @@ -2400,12 +2401,14 @@ private async Task ReadAndHandleRequestsAsync()
return;
}
}
catch (OperationCanceledException)
catch (OperationCanceledException ex) when (this.DisconnectedToken.IsCancellationRequested)
{
loopBreakingException = ex;
break;
}
catch (ObjectDisposedException)
catch (ObjectDisposedException ex) when (this.IsDisposed)
{
loopBreakingException = ex;
break;
}
#pragma warning disable CA1031 // Do not catch general exception types
Expand All @@ -2426,7 +2429,7 @@ private async Task ReadAndHandleRequestsAsync()
(this.MessageHandler as IJsonRpcMessageBufferManager)?.DeserializationComplete(protocolMessage);
}

this.OnJsonRpcDisconnected(new JsonRpcDisconnectedEventArgs(Resources.StreamDisposed, DisconnectedReason.LocallyDisposed));
this.OnJsonRpcDisconnected(new JsonRpcDisconnectedEventArgs(Resources.StreamDisposed, DisconnectedReason.LocallyDisposed, loopBreakingException));
}
catch (Exception ex)
{
Expand Down

0 comments on commit 9bd73af

Please sign in to comment.