In StreamingWebSocketClient.CloseDisposeAndClearRequestsAsync
CancellationTokenSource tokenSource = null;
try
{
if (_clientWebSocket != null && (_clientWebSocket.State == WebSocketState.Open || _clientWebSocket.State == WebSocketState.Connecting))
{
tokenSource = new CancellationTokenSource(ConnectionTimeout);
await _clientWebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "",
tokenSource.Token).ConfigureAwait(false);
while (_clientWebSocket.State != WebSocketState.Closed && !tokenSource.IsCancellationRequested) ;
}
}
catch { }
finally
{
tokenSource?.Dispose();
}
This while is CPU eater, use Task.Delay.
The websocket never closed for some reason. (thats make that while go crazy on the CPU)
Expected Behavior
Websocket closed and my CPU are safe
Current Behavior
While loop eat the CPU because websocket state never be Closed (WebSocketState.Closed)
Possible Solution
- Look for what case the websocket state not updated.
- Add
Task.Delay for 1.0 or 0.5 sec even if the close problem fixed.
Steps to Reproduce
- call
StreamingWebSocketClient.StartAsync()
- call
StreamingWebSocketClient.Dispose() or StreamingWebSocketClient.StopAsync()
In
StreamingWebSocketClient.CloseDisposeAndClearRequestsAsyncThis while is CPU eater, use
Task.Delay.The websocket never closed for some reason. (thats make that
whilego crazy on the CPU)Expected Behavior
Websocket closed and my CPU are safe
Current Behavior
While loop eat the CPU because websocket state never be Closed (WebSocketState.Closed)
Possible Solution
Task.Delayfor 1.0 or 0.5 sec even if the close problem fixed.Steps to Reproduce
StreamingWebSocketClient.StartAsync()StreamingWebSocketClient.Dispose()orStreamingWebSocketClient.StopAsync()