From 054833dd1ae5ac497b102f88dd925d5bcde32336 Mon Sep 17 00:00:00 2001 From: Steven Portley Date: Thu, 5 Mar 2026 11:50:26 -0800 Subject: [PATCH] Add retry w/ timeout around LIBUSB_ERROR_ACCESS It is possible for a device to enumerate on the bus and for libhoth to attempt to connect to it before udev has the opportunity to adjust the permissions. This is very common when attempting to reconnect and results in LIBUSB_ERROR_ACCESS failures during DFU updates. --- transports/libhoth_usb.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/transports/libhoth_usb.c b/transports/libhoth_usb.c index bee2865..6b18c6c 100644 --- a/transports/libhoth_usb.c +++ b/transports/libhoth_usb.c @@ -193,9 +193,26 @@ static int libhoth_usb_device_open( usb_dev->info = info; usb_dev->ctx = options->usb_ctx; usb_dev->claim_timeout_us = options->timeout_us; - status = libusb_open(options->usb_device, &usb_dev->handle); - if (status != LIBUSB_SUCCESS) { - goto err_out; + + uint32_t wait_time_us = 0; + while (true) { + status = libusb_open(options->usb_device, &usb_dev->handle); + + if (status == LIBUSB_SUCCESS) { + break; + } + + if (status != LIBUSB_ERROR_ACCESS) { + goto err_out; + } + + if (wait_time_us >= options->timeout_us) { + // timeout + goto err_out; + } + + usleep(1000); + wait_time_us += 1000; } dev->send = libhoth_usb_send_request;