-
Notifications
You must be signed in to change notification settings - Fork 302
fixing tcp_interface 100% cpu usage bug (#709) #761
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
Conversation
|
|
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 addresses the 100% CPU usage bug in the TCP interface by adding logic to detect when a disconnected socket returns an empty byte string and then reconnecting accordingly.
- Added a check for an empty byte string in _readBytes to trigger a socket reconnect
- Standardized socket checks using "is not None" and updated calls to the superclass
- Introduced contextlib.suppress to safely handle exceptions during shutdown
Comments suppressed due to low confidence (2)
meshtastic/tcp_interface.py:40
- [nitpick] Consider renaming 'myConnect' to a more descriptive name such as 'reconnect' or 'establishConnection' to improve code clarity.
self.myConnect()
meshtastic/tcp_interface.py:93
- [nitpick] Ensure that calling '_startConfig()' after reconnection properly reinitializes all necessary configurations to prevent potential runtime issues.
self._startConfig()
| """ | ||
| if self.socket: #mian: please check that this should be "if self.socket:" | ||
| cast(socket.socket, self.socket).shutdown(socket.SHUT_RDWR) | ||
| if self.socket is not None: |
Copilot
AI
Apr 15, 2025
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.
Remove the obsolete inline comment containing 'mian', as it is no longer applicable.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #761 +/- ##
==========================================
- Coverage 60.13% 59.98% -0.15%
==========================================
Files 24 24
Lines 4066 4076 +10
==========================================
Hits 2445 2445
- Misses 1621 1631 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The issue identified in #709 occurs when the TCP socket gets disconnected after a period of time. In this case, socket.recv() doesn’t raise an exception but instead returns an empty byte string (b''), which causes the _reader thread to enter a tight infinite loop.
This fix adds a check for that condition and performs a socket reconnect when it occurs.