From 94591eee6d6494ab155987785a1fb3149a7e39e6 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 17 Jul 2024 18:01:45 +0000 Subject: [PATCH] Capture OperationCanceledException (instead of TaskCanceledException) The former is the base class for the latter, so this will widen the umbrella to catch a few corner cases that would otherwise been handled by the generic "Exception" catch block. One corner case I know of is when an op is canceled via "CancellationToken.ThrowIfCancellationRequested". In that case, an OperationCanceledException is thrown (not a TaskCanceledException). https://stackoverflow.com/questions/34359129/operationcanceledexception-vs-taskcanceledexception-when-task-is-canceled --- .../spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs b/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs index de2c01c44..d5e4b5329 100644 --- a/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs +++ b/src/client/spark_websocket/JsonRpc/JsonRpcRequestAsyncEnumerable.cs @@ -39,7 +39,7 @@ public class JsonRpcRequestAsyncEnumerable { var offsetBuffer = new ArraySegment(buffer, offset, buffer.Length - offset); try { return await webSocket.ReceiveAsync(offsetBuffer, cancellationToken); - } catch (TaskCanceledException) { + } catch (OperationCanceledException) { logger.LogTrace("JsonRpcRequestAsyncEnumerable 'ReceiveAsync' task was cancelled (exiting gracefully)."); } catch (Exception ex) { logger.LogError("JsonRpcRequestAsyncEnumerable Exception while awaiting request: {Exception}", ex);