meshtastic / python

The Python CLI and API for talking to Meshtastic devices
https://meshtastic.org
379 stars 160 forks source link

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

Closed ScriptBlock closed 3 years ago

ScriptBlock commented 3 years ago

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:

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

geeksville commented 3 years ago

thanks for the report - I'll work on this todayu.

geeksville commented 3 years ago

fixed in 1.1.32 - thanks for the report!