some fixes

This commit is contained in:
Ayzen
2026-06-05 14:40:10 +03:00
parent 22942d9dc9
commit bbea744459
35 changed files with 1797 additions and 297 deletions
@@ -157,8 +157,19 @@ class USBTransport:
logger.debug("USB disconnect requested")
self._stop_event.set()
if self._rx_thread is not None and self._rx_thread.is_alive():
self._rx_thread.join(timeout=1.0)
rx_thread = self._rx_thread
if rx_thread is not None and rx_thread.is_alive():
rx_thread.join(timeout=1.0)
if rx_thread.is_alive():
# The RX thread is wedged inside libusb; closing the handle or
# context now would risk a use-after-free in the still-running
# bulkRead. Deliberately leak both rather than crash the process.
logger.error(
"USB RX thread did not stop within timeout; leaking USB handle/context "
"to avoid use-after-free (serial=%s)",
self.connected_serial,
)
return
self._rx_thread = None
if self._handle is not None: