Skip to content

Commit

Permalink
Merge pull request #476 from AArnott/traceTransmissionFailures
Browse files Browse the repository at this point in the history
Trace message transmission failures
  • Loading branch information
AArnott authored Jun 22, 2020
2 parents 8d7809e + 6f50746 commit 18d079d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/StreamJsonRpc.Tests/JsonRpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,18 @@ public async Task ReportProgressWithUnserializableData_LeavesTraceEvidence()
}
}

[Fact]
public async Task NotifyAsync_LeavesTraceEvidenceOnFailure()
{
var exception = await Assert.ThrowsAnyAsync<Exception>(() => this.clientRpc.NotifyAsync("DoesNotMatter", new TypeThrowsWhenSerialized()));

// Verify that the trace explains what went wrong with the original exception message.
while (!this.clientTraces.Messages.Any(m => m.Contains("Can't touch this")))
{
await this.clientTraces.MessageReceived.WaitAsync(this.TimeoutToken);
}
}

[Fact]
public async Task InvokeWithParameterObject_ProgressParameterAndFields()
{
Expand Down
16 changes: 11 additions & 5 deletions src/StreamJsonRpc/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ public enum TraceEvents
/// Thus a failure recorded in this event may be followed by a successful deserialization to another parameter type and invocation of a different overload.
/// </remarks>
MethodArgumentDeserializationFailure,

/// <summary>
/// An outgoing RPC message was not sent due to an exception, possibly a serialization failure.
/// </summary>
TransmissionFailed,
}

/// <summary>
Expand Down Expand Up @@ -1721,11 +1726,6 @@ private RemoteRpcException CreateExceptionFromRpcError(JsonRpcError response, st
{
throw new ConnectionLostException(Resources.ConnectionDropped, ex);
}
catch (Exception)
{
this.OnRequestTransmissionAborted(request);
throw;
}
}

private JsonRpcError CreateError(JsonRpcRequest request, Exception exception)
Expand Down Expand Up @@ -2592,6 +2592,12 @@ private async ValueTask TransmitAsync(JsonRpcMessage message, CancellationToken
this.OnJsonRpcDisconnected(e);
}

this.TraceSource.TraceEvent(TraceEventType.Error, (int)TraceEvents.TransmissionFailed, "Exception thrown while transmitting message: {0}", exception);
if (message is JsonRpcRequest request)
{
this.OnRequestTransmissionAborted(request);
}

throw;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/StreamJsonRpc/netcoreapp2.1/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
StreamJsonRpc.DisconnectedReason.RemoteProtocolViolation = 6 -> StreamJsonRpc.DisconnectedReason
StreamJsonRpc.JsonRpc.DispatchCompletion.get -> System.Threading.Tasks.Task!
StreamJsonRpc.JsonRpc.TraceEvents.TransmissionFailed = 18 -> StreamJsonRpc.JsonRpc.TraceEvents
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.get -> int
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.set -> void
StreamJsonRpc.JsonRpcTargetOptions.UseSingleObjectParameterDeserialization.get -> bool
Expand Down
1 change: 1 addition & 0 deletions src/StreamJsonRpc/netstandard2.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
StreamJsonRpc.DisconnectedReason.RemoteProtocolViolation = 6 -> StreamJsonRpc.DisconnectedReason
StreamJsonRpc.JsonRpc.DispatchCompletion.get -> System.Threading.Tasks.Task!
StreamJsonRpc.JsonRpc.TraceEvents.TransmissionFailed = 18 -> StreamJsonRpc.JsonRpc.TraceEvents
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.get -> int
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.set -> void
StreamJsonRpc.JsonRpcTargetOptions.UseSingleObjectParameterDeserialization.get -> bool
Expand Down

0 comments on commit 18d079d

Please sign in to comment.