fixing tcp_interface 100% cpu usage bug (#709)#761
fixing tcp_interface 100% cpu usage bug (#709)#761ianmcorvidae merged 1 commit intomeshtastic:masterfrom derekn:master
Conversation
|
|
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.