Repository navigation
Meshtastic CLI Disconnect Read Failure #855
Copy link
Copy link
Closed
Description
Hardware: tbeam
Firmware: 2.6.11.60ec05e
Meshtastic CLI Version: 2.7.4
After successfully running a command using the CLI, the Serial Stream doesn't close properly.
Example command and error:
$ meshtastic --info
Connected to radio
Owner: joebishop (a8f8)
My info: { "myNodeNum": 240560376, "rebootCount": 3, "minAppVersion": 30200, "pioEnv": "tbeam", "deviceId": "", "firmwareEdition": "VANILLA", "nodedbCount": 0 }
Metadata: { "firmwareVersion": "2.6.11.60ec05e", "deviceStateVersion": 24, "canShutdown": true, "hasWifi": true, "hasBluetooth": true, "positionFlags": 811, "hwModel": "TBEAM", "hasPKC": true, "excludedModules": 1280, "hasEthernet": false, "role": "CLIENT", "hasRemoteHardware": false }
<all node information like normal, snipped for brevity>
Primary channel URL: https://meshtastic.org/e/#CgcSAQE6AggNEgwIATgBQANIAVAaeEA
ERROR file:stream_interface.py __reader line:227 Unexpected exception, terminating meshtastic reader... 'NoneType' object cannot be interpreted as an integer
Some initial troubleshooting shows commands work, but the error is thrown at the end of the session. Regardless of which option is used, (--nodes, --set lora.region US, etc) the error shows up. The command executes successfully against the node, but it appears closing the stream has a failure.
Traceback is shown when using --port /dev/ACM#. Full system path cut for brevity.
WARNING file:stream_interface.py __reader line:216 Meshtastic serial port disconnected, disconnecting... read failed: [Errno 9] Bad file descriptor
Exception in thread stream reader:
Traceback (most recent call last):
File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
self.run()
File "/usr/lib/python3.12/threading.py", line 1010, in run
self._target(*self._args, **self._kwargs)
File "./meshtastic/.meshtastic/lib/python3.12/site-packages/meshtastic/stream_interface.py", line 232, in __reader
self._disconnected()
File "./meshtastic/.meshtastic/lib/python3.12/site-packages/meshtastic/stream_interface.py", line 98, in _disconnected
self.stream.close()
File "./meshtastic/.meshtastic/lib/python3.12/site-packages/serial/serialposix.py", line 533, in close
os.close(self.fd)
OSError: [Errno 9] Bad file descriptor
Thanks for looking into this. I'm happy to provide any additional information or troubleshooting steps.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
ianmcorvidae commentedon Nov 9, 2025
@SpudGunMan thinking this could be related to your change. Is there anything you can see here?
SpudGunMan commentedon Nov 10, 2025
Like issues covered before? Yes the errors have been all along imo, the close was just removing the time wait close close before.. so the issue is out side the scope of the interface close at the end?
SpudGunMan commentedon Nov 10, 2025
Add a wait/sleep before closing to slow it down for serial?
ogarcia commentedon Nov 10, 2025
I have exactly the same problem with a Heltec v3 connected via serial port to
/dev/ttyUSB0.And I don't know if it's related, but when I change a parameter with
--set, I get this other error:SpudGunMan commentedon Nov 10, 2025
The command will work it looks like as well? But the error is after set?
ogarcia commentedon Nov 10, 2025
The command works correctly (it sets and changes the value) but gives an error. This is what it says when fully executed when changing any value:
The same error also occurs if you use
--export-config(at the very end):SpudGunMan commentedon Nov 10, 2025
I'm not near a keyboard but was pondering via 🤖 the issue just leaks, question isn't so much the patch but how to find the drip?
I had these errors prior, it's just cleaning them properly?
Here’s the direct analysis and a suggested fix for the bug in meshtastic/python issue #855, based on the code at
meshtastic/stream_interface.py, specifically in the__readermethod and its call to_disconnected.🤖Diagnosis:
'NoneType' object cannot be interpreted as an integer) andOSError: [Errno 9] Bad file descriptorare triggered during cleanup.finallyclause of__reader,self._disconnected()is called. That method attempts toself.stream.close()(if not None).self.streamis already closed, set toNone, or itsfdis invalid by the time this code runs—potentially because an exception in serial communication or double cleanup occurs.Target fix area:
_disconnectedneeds to robustly check the stream and its properties before closing, ideally inside atry/except(ignoring already-closed descriptors).Patch sketch:
This type of change should prevent attempts to close an already-closed stream and gracefully ignore related errors.
ianmcorvidae commentedon Nov 10, 2025
It looks like the
is_openproperty doesn't update right away, or something. I couldn't get a version similar to that to work, because it'd claim to be open and then throw the error. For now, I just wrapped it in another try-catch. It's a bit ugly, but I'd rather it try to close it twice than fail to close it, so.ianmcorvidae commentedon Nov 10, 2025
Accordingly, should be fixed in dbc0101
wintermute101 commentedon Nov 13, 2025
I installed version commit 0906fc6
Still have same error:
ianmcorvidae commentedon Nov 13, 2025
Hm, okay, that must be another error. I added some additional logging and fixed one error that the tests found in f15a0bd -- if you're able to, would you mind testing again with that commit?
wintermute101 commentedon Nov 13, 2025
Here you go:
ianmcorvidae commentedon Nov 13, 2025
Yeah, I see that the CI version of the tests failed as well. I'm reverting a bunch of stuff to get this back to how it was before.
ianmcorvidae commentedon Nov 13, 2025
Reverted all of the stuff refactoring how
closeand such work in 1088cc6wintermute101 commentedon Nov 13, 2025
Info now works fine! :)
Primary channel URL: https://meshtastic.org/e/#CgcSAQE6AggNEhgIARAGGPoBIAsoBTgDQANIAVAbaAHABgEno errors
there is some issue with reboot (on rpi pico - when reboot port goes out) but it is not related to this issue.
SpudGunMan commentedon Nov 13, 2025
My original hunt was to find why I was seeing it so much in api runtime
I wonder if the original idea needed a wait or a none check to avoid the extra errors.
Sorry for the problems
SpudGunMan commentedon Nov 13, 2025
One random thing I did notice either related to this or firmware patches.
Disconnect reconnect was or is working better under current release's
SpudGunMan commentedon Nov 13, 2025
I also wonder if the work JB was tracking on WiFi issues and platform are in anyway related?