Skip to content

Commit 0ae7348

Browse files
author
kgrudzien
committed
try catch in CloseAsync when cancellation requested
1 parent 403e257 commit 0ae7348

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

data-api/csharp-ws/CoinAPI.WebSocket.V1/CoinApiWsClient.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,19 @@ private async Task HandleConnection(CancellationTokenSource connectionCts)
340340
}
341341
catch (TaskCanceledException)
342342
{
343-
if (_client.State == WebSocketState.Open)
343+
try
344+
{
345+
if (_client.State == WebSocketState.Open)
346+
{
347+
await _client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Normal", CancellationToken.None);
348+
349+
}
350+
351+
}
352+
catch (Exception ex)
344353
{
345-
await _client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Normal", CancellationToken.None);
346354

355+
OnError(ex);
347356
}
348357
}
349358
catch (Exception ex)

0 commit comments

Comments
 (0)