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

WebSocketClient, fixed starvation condition #738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bridgedragon
Copy link

@bridgedragon bridgedragon commented Nov 20, 2021

If method "HandleIncomingMessagesAsync()" is called before the websocket client is connected, the while() loop will get stuck in starvation condition, making continuous comparison without any CPU pause. This won't allow "_clientWebSocket" to connect, because CPU is stuck in that method, not allowing any other tasks to continue.

I propose initializing the listener when "_clientWebSocket" is already connected. May I propose other solutions, with an AutoResetEvent variable setted when a request is added to "_requests", if you do not like to initialize the listener at this point.

Starvation condition is tested and triggered in Ubuntu 21.04 (and I suppose it is happening in another OS). When "StreamingWebSocketClient" is instantiated in any project, the program will be stuck by 100% CPU usage.

snake-4 added a commit to snake-4/Nethereum that referenced this pull request Nov 20, 2021
made StopAsync and StartAsync thread-safe. Implemented the fix for Nethereum#738. Fixed the problem where the _listener task completed immediately. The listener now quits when the WebSocket disconnects.
snake-4 added a commit to snake-4/Nethereum that referenced this pull request Nov 20, 2021
made StopAsync and StartAsync thread-safe. Implemented the fix for Nethereum#738. Fixed the problem where the _listener task completed immediately. Also, the listener now quits when the WebSocket disconnects.
snake-4 added a commit to snake-4/Nethereum that referenced this pull request Nov 20, 2021
made StopAsync and StartAsync thread-safe. Implemented the fix for Nethereum#738. Fixed the problem where the _listener task completed immediately. Also, the listener now quits when the WebSocket disconnects.
@juanfranblanco
Copy link
Member

As per other threads.. (and new people coming over) I did not see any mayor improvements but keeping it open, in case it helps others.

@distoken001
Copy link

管理员在吗 快点把这个pr合并了

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

Successfully merging this pull request may close these issues.

None yet

3 participants