Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamingWebSocketClient never close #998

Open
CorrM opened this issue Dec 20, 2023 · 2 comments
Open

StreamingWebSocketClient never close #998

CorrM opened this issue Dec 20, 2023 · 2 comments

Comments

@CorrM
Copy link

CorrM commented Dec 20, 2023

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

  1. Look for what case the websocket state not updated.
  2. Add Task.Delay for 1.0 or 0.5 sec even if the close problem fixed.

Steps to Reproduce

  1. call StreamingWebSocketClient.StartAsync()
  2. call StreamingWebSocketClient.Dispose() or StreamingWebSocketClient.StopAsync()
@juanfranblanco
Copy link
Member

Yes that will help, although why is your web socket not disconnecting straight away?

@CorrM
Copy link
Author

CorrM commented Dec 20, 2023

I have no idea, i use Infura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants