Skip to content

Commit d772b6a

Browse files
author
Dean Ward
authored
Fix an unobserved task exception (#188)
* Fix an unobserved task exception Addresses an unobserved exception that occurs when an `ObjectDisposedException` is raised after a `CancellationToken` is cancelled by only cancelling if the token has not been previously cancelled. The default `catch` will fire for an `OperationCanceledException` and then attempt to cancel the same `CancellationToken` that was just cancelled. * `try/catch` the call to `Cancel`, add a comment
1 parent 2060c3c commit d772b6a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/protobuf-net.Grpc/Internal/Reshape.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,14 @@ static async Task SendAll<T>(IClientStreamWriter<T> output, IAsyncEnumerable<T>
520520
}
521521
catch
522522
{
523-
allDone.Cancel();
523+
if (!allDone.IsCancellationRequested)
524+
{
525+
try
526+
{
527+
allDone.Cancel();
528+
}
529+
catch { } // calls to "Cancel" can race, ignore the exception if we lose the race
530+
}
524531
throw;
525532
}
526533
}

0 commit comments

Comments
 (0)