Improve websocket stability, timeouts and logging#83
Open
pyroch wants to merge 1 commit intoolijeffers0n:masterfrom
Open
Improve websocket stability, timeouts and logging#83pyroch wants to merge 1 commit intoolijeffers0n:masterfrom
pyroch wants to merge 1 commit intoolijeffers0n:masterfrom
Conversation
Owner
|
Have you noticed issues from sending ping packets? I believe I explicitly disabled this in the past due to it causing issues where the server wouldn't actually reply. |
olijeffers0n
reviewed
Apr 8, 2026
| app_message.parse(data) | ||
|
|
||
| except ConnectionClosedError as e: | ||
| except asyncio.TimeoutError: |
Owner
There was a problem hiding this comment.
If you are only waiting 30 seconds for a packet, but you just are not sending anything at that current moment, that is going to cause you to cycle through connections super fast despite not actually needing to, surely?
olijeffers0n
reviewed
Apr 8, 2026
| self.connection = None | ||
|
|
||
| async def run(self) -> None: | ||
| RECV_TIMEOUT = 30 |
Owner
There was a problem hiding this comment.
This should be a file-level static variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves websocket reliability and reduces resource usage.
Added websocket keepalive:
Added recv timeout (30s) to prevent hanging connections
Handle asyncio.TimeoutError and close stale connections
Handle ConnectionClosedOK (normal close)
Reduced logging overhead:
replaced logger.exception with logger.error
removed unnecessary traceback logging
Simplified connection error handling
Why?
Between rust server restarts the ws sends a huge amount of logs (even if supressed in logger - it takes CPU).
This causes big CPU spikes when you waiting for rust server to restarts (usually happens every day).
This fix resolves that behaivour
Previously:
websocket could hang indefinitely on recv()
dead connections were not detected
excessive traceback logging increased CPU usage !!!
Now:
stale connections are detected and closed
keepalive ensures connection health
logging is lighter and cleaner
I have it tested on my server with py-spy - difference is about 4400 samples without fix vs 40 samples with fix

Also you can see on grafana graph that is CPU usage now is not even going up between rust server restarts
No breaking changes.