some fixes again

This commit is contained in:
Ayzen
2026-06-05 17:50:59 +03:00
parent bbea744459
commit 3c30a12d4a
24 changed files with 209 additions and 157 deletions
@@ -173,12 +173,21 @@ class USBTransport:
self._rx_thread = None
if self._handle is not None:
self._handle.releaseInterface(self.INTERFACE)
self._handle.close()
# Always release AND close the handle, even if releaseInterface raises on
# a vanished/changed device. Otherwise the handle leaks with the interface
# still claimed, and every subsequent connect() fails forever with
# "Failed to claim USB interface" (LIBUSB_ERROR_BUSY) — the device never
# recovers after a hot-unplug/replug. close() releases the claim at the OS
# level regardless, so reconnect can claim it again.
with suppress(usb1.USBError):
self._handle.releaseInterface(self.INTERFACE)
with suppress(usb1.USBError):
self._handle.close()
self._handle = None
if self._ctx is not None:
self._ctx.close()
with suppress(usb1.USBError):
self._ctx.close()
self._ctx = None
logger.info("USB disconnected (serial=%s)", self.connected_serial)