Commit Graph
30 Commits
Author SHA1 Message Date
Thomas Göttgens f623732694 Half-close TCP connections so the last write is not lost
close() went straight to shutdown(SHUT_RDWR) + close(). Doing that while either
side still has unread data makes the stack send RST rather than FIN, and the
device's FromRadio stream means there is essentially always unread data.

Winsock discards data that was received but not yet read when an RST arrives, so
an admin message written moments earlier is thrown away before the device reads
it. Linux delivers the buffered bytes before reporting ECONNRESET, which is why
this only surfaced on Windows: every one-shot TCP write there (--set, --seturl,
--sendtext) reported success and did nothing.

writeConfig() does not wait for an ack, so close() runs microseconds after
sendall(). The device cannot compensate; it polls every 5ms and the RST beats its
next read.

Send FIN first with shutdown(SHUT_WR), which lets the device consume what we
wrote, wait briefly for the reader thread to drain and exit, then tear down
exactly as before. The full shutdown is kept so a reader still blocked in recv()
is unblocked for the join in StreamInterface.close(). The wait is bounded: the
device is not obliged to close just because we half-closed.

Fixes #957
2026-07-17 14:34:18 +02:00
Ian McEwen dbf4cabee1 Avoid deadlocking on potentially re-entrant _startConfig call, and don't reconnect when _wantExit 2026-05-31 15:03:58 -07:00
Ian McEwen 435e53eae2 Re-establish the OSError being raised to match former behavior, but still reconnect. TBD if this is quite the right approach. 2026-05-31 14:53:46 -07:00
Ian McEwen 12509bef30 Merge branch 'master' into review/pr-901 2026-05-31 14:30:04 -07:00
Ian McEwen 02485a88fb some pre-merge cleanup 2026-05-31 14:23:34 -07:00
Ian McEwen ce5bbcda68 Fix some leaks/hangs on close: unstarted StreamInterface streams & TCP reader unblock 2026-05-31 13:48:06 -07:00
Ian McEwen c2a01f8294 fix a missing paren in a comment 2026-05-31 13:35:24 -07:00
Stephen Thorne 07172f88f3 Give TCPInterface reconnect logic on write errors
* Moving to socket.sendall() is safer, as sendall will send the entire
   buffer, while send() would return the number of bytes sent and
   require being called multiple times if the buffer was full.
 * On exceptions: reconnect to the server.
 * On reconnection: make sure using a lock that there isn't a race
   between the readers and the writers triggering a reconnect.
2026-02-05 22:46:40 +01:00
Travis-L-R 76418b8e57 Reorganising connect method calls for when connectNow is false 2025-11-11 19:25:51 +10:30
Travis-L-R 3be73b42e2 Removing unnecessary initialization of self.stream in TCPInterface 2025-11-11 19:19:44 +10:30
horrible-knots 2de7c30a27 Plumb timeout from --timeout through MeshInterface
Fix C0301: Line too long

Ignore the pylint for 6 positional arguments
2025-10-13 17:35:30 -04:00
shukari db1891b651 Added Logging Handler Names 2025-08-06 18:21:32 +02:00
Ian McEwen 622a435465 Add __repr__ methods to interface types and Node, for nicer printing/logging 2025-05-08 21:23:00 -07:00
Derek Nicol 2e73fe310c fixing tcp_interface 100% cpu usage bug (#709) 2025-04-15 15:23:09 -05:00
Ian McEwen 20d75d9023 Merge branch 'master' into wls_add_types2 2024-10-29 06:19:16 -07:00
Ian McEwen 0523d4c94f disable R0917 pylint failures 2024-10-12 12:49:14 -07:00
William Stearns 0da405168f pylint cleanups 2024-10-10 23:49:20 -04:00
William Stearns aba381fb54 Merge branch 'master' into wls_add_types 2024-10-08 23:28:25 -04:00
DJ Holt 5cc9627e21 Refactor default port number to variable 2024-09-16 23:41:44 -06:00
William Stearns a29ee840f2 Adding mypy typing 2024-06-15 23:22:43 -04:00
Ian McEwen e6d61c6603 Allow a faster nodedb-less startup on 2.3.11+ with --no-nodes and the magic value from meshtastic/firmware#3949 2024-06-05 18:52:35 -07:00
Ian McEwen 4baef92523 Fix assorted mypy-detected errors 2024-03-29 18:38:25 -07:00
Thomas Göttgens 7e6f13f0a2 establish trunk format 2023-03-31 20:09:59 +02:00
Mike Kinney ad8f2222db cover a few more lines 2022-01-12 16:50:29 -08:00
Mike Kinney 5c662822b9 need to fully qualify imports so projects consuming the library will work 2022-01-05 11:16:08 -08:00
Mike Kinney 614a90c0eb unit test a few more lines 2021-12-30 22:59:01 -08:00
Mike Kinney a243fab9af figured out how to unit test __reader() 2021-12-25 11:39:04 -08:00
Mike Kinney 2fcfdeb04f minor formatting; added unit tests for Node() 2021-12-16 09:10:45 -08:00
Mike Kinney 6d2a187d38 fix pylint warnings 2021-12-06 23:01:34 -08:00
Mike Kinney b40eb08c5c refactor classes into respective files 2021-12-06 22:19:26 -08:00