Skip to content

Commit 18d079d

Browse files
authored
Merge pull request #476 from AArnott/traceTransmissionFailures
Trace message transmission failures
2 parents 8d7809e + 6f50746 commit 18d079d

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/StreamJsonRpc.Tests/JsonRpcTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,18 @@ public async Task ReportProgressWithUnserializableData_LeavesTraceEvidence()
955955
}
956956
}
957957

958+
[Fact]
959+
public async Task NotifyAsync_LeavesTraceEvidenceOnFailure()
960+
{
961+
var exception = await Assert.ThrowsAnyAsync<Exception>(() => this.clientRpc.NotifyAsync("DoesNotMatter", new TypeThrowsWhenSerialized()));
962+
963+
// Verify that the trace explains what went wrong with the original exception message.
964+
while (!this.clientTraces.Messages.Any(m => m.Contains("Can't touch this")))
965+
{
966+
await this.clientTraces.MessageReceived.WaitAsync(this.TimeoutToken);
967+
}
968+
}
969+
958970
[Fact]
959971
public async Task InvokeWithParameterObject_ProgressParameterAndFields()
960972
{

src/StreamJsonRpc/JsonRpc.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ public enum TraceEvents
381381
/// Thus a failure recorded in this event may be followed by a successful deserialization to another parameter type and invocation of a different overload.
382382
/// </remarks>
383383
MethodArgumentDeserializationFailure,
384+
385+
/// <summary>
386+
/// An outgoing RPC message was not sent due to an exception, possibly a serialization failure.
387+
/// </summary>
388+
TransmissionFailed,
384389
}
385390

386391
/// <summary>
@@ -1721,11 +1726,6 @@ private RemoteRpcException CreateExceptionFromRpcError(JsonRpcError response, st
17211726
{
17221727
throw new ConnectionLostException(Resources.ConnectionDropped, ex);
17231728
}
1724-
catch (Exception)
1725-
{
1726-
this.OnRequestTransmissionAborted(request);
1727-
throw;
1728-
}
17291729
}
17301730

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

2595+
this.TraceSource.TraceEvent(TraceEventType.Error, (int)TraceEvents.TransmissionFailed, "Exception thrown while transmitting message: {0}", exception);
2596+
if (message is JsonRpcRequest request)
2597+
{
2598+
this.OnRequestTransmissionAborted(request);
2599+
}
2600+
25952601
throw;
25962602
}
25972603
}

src/StreamJsonRpc/netcoreapp2.1/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
StreamJsonRpc.DisconnectedReason.RemoteProtocolViolation = 6 -> StreamJsonRpc.DisconnectedReason
22
StreamJsonRpc.JsonRpc.DispatchCompletion.get -> System.Threading.Tasks.Task!
3+
StreamJsonRpc.JsonRpc.TraceEvents.TransmissionFailed = 18 -> StreamJsonRpc.JsonRpc.TraceEvents
34
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.get -> int
45
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.set -> void
56
StreamJsonRpc.JsonRpcTargetOptions.UseSingleObjectParameterDeserialization.get -> bool

src/StreamJsonRpc/netstandard2.0/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
StreamJsonRpc.DisconnectedReason.RemoteProtocolViolation = 6 -> StreamJsonRpc.DisconnectedReason
22
StreamJsonRpc.JsonRpc.DispatchCompletion.get -> System.Threading.Tasks.Task!
3+
StreamJsonRpc.JsonRpc.TraceEvents.TransmissionFailed = 18 -> StreamJsonRpc.JsonRpc.TraceEvents
34
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.get -> int
45
StreamJsonRpc.JsonRpcEnumerableSettings.Prefetch.set -> void
56
StreamJsonRpc.JsonRpcTargetOptions.UseSingleObjectParameterDeserialization.get -> bool

0 commit comments

Comments
 (0)