Skip to content

Python TCP interface.close() blocking until message is sent or arrives #49

Description

@ScriptBlock

See forum post for initial detail about this issue: https://meshtastic.discourse.group/t/python-tcp-interface-close-blocking-for-arbitrary-amount-of-time/2035/1.

Description: calling interface.close() doesn't close the connection until an event arrives on the meshtastic.receive topic regardless of whether we are subscribed to that topic or not. I have worked around this issue by adding an explicit data sent command just before interface.close(). Using sendText is undesirable because I don't want messages to show up for every API open/close so I do:
interface.sendData(b'api closing')
just before I call interface.close() and this reliably allows the interface to close every time.
I have also tried explicitly unsubscribing from all topics, but that doesn't have any effect.

The example script is in the forum post, but it's literally just creating a new TCPInterface and then calling close on it with nothing in between.

To Reproduce
Run the python script. The first run of the script will work successfully. Subsequent runs will fail to close in a timely manner. Unblock by sending/receiving a message.

Expectation
Every time I call interface.close(), I shouldn't have to wait any significant amount of time for it to close and it should close regardless of whether there's messages on the message topic.

Device info:

  • Device model: tbeam
  • Software Version: 1.1.30

Additional Context
Here's a doc that contains the serial output from multiple runs.
https://docs.google.com/document/d/1QnsyCvWVey8a6hTCSooTRB6YhtqSoZEckWCGA0QG9U4/edit?usp=sharing

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions