-
Notifications
You must be signed in to change notification settings - Fork 288
Fix messages are one-behind when using secure sockets (wss) #298
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
base: master
Are you sure you want to change the base?
Fix messages are one-behind when using secure sockets (wss) #298
Conversation
This fix tries to query the sockets directly for pending data if poller.poll() returns no file descriptors. In case of pending data, a special flag is set on the websocket, to ensure the whole buffer is processed in one go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where messages on secure sockets (wss) are processed one message behind by querying sockets directly when poller.poll() fails to return file descriptors. Key changes include introducing a special flag (_force_process_buffer) in the websocket to trigger full buffer processing, and adding a helper method in the manager to detect and handle pending data on secure sockets.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
ws4py/websocket.py | Introduces _force_process_buffer and extends the message processing loop in once(). |
ws4py/manager.py | Adds get_fds_with_pending_data to check for pending socket data and set the flag. |
Comments suppressed due to low confidence (1)
ws4py/manager.py:297
- [nitpick] Ensure that ws.sock.pending() returns a boolean as expected. If it returns an integer or another type, consider making the check explicit (e.g. checking for a positive value) to improve code clarity.
if hasattr( ws.sock, 'pending' ) and ws.sock.pending():
@@ -424,6 +429,15 @@ def once(self): | |||
if not self.process(self.buf[:requested]): | |||
return False | |||
self.buf = self.buf[requested:] | |||
if self.buf and self._force_process_buffer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The while loop for processing the buffer under special handling mode duplicates some logic found earlier in the method. Consider refactoring this loop into a separate helper method to improve readability and maintainability.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add unit tests to verify the changes?
Sure. I've already prepared an integration test in pytest for our system. I will refactor the test to use |
thank you. will be looking forward to it |
This fix tries to query the sockets directly for pending data if poller.poll() returns no file descriptors.
In case of pending data, a special flag is set on the websocket, to ensure the whole buffer is processed in one go.
Fixes #270