Skip to content

USB HCI transport teardown — usbi_mutex abort on close#963

Open
greateggsgreg wants to merge 1 commit into
google:mainfrom
greateggsgreg:usb-hci-transport-teardown-fix
Open

USB HCI transport teardown — usbi_mutex abort on close#963
greateggsgreg wants to merge 1 commit into
google:mainfrom
greateggsgreg:usb-hci-transport-teardown-fix

Conversation

@greateggsgreg

Copy link
Copy Markdown
Contributor

Closing the USB HCI transport (a Nordic nRF52840 Zephyr dongle, usb:2fe3:000b) aborts

UsbPacketSink.terminate() cancels its OUT transfer but reaps it via a shared semaphore
that a prior completion can pre-release, so a cancellation may go unreaped; and the transfer objects are
freed implicitly by python-libusb1's USBDeviceHandle.close() rather than explicitly after the join.
libusb_free_transfer() on a still-active transfer is illegal and destroys its mutex mid-use

Reproduce

Run repeated BLE sessions over the nRF USB HCI transport and close each; the abort fires at teardown
(exit 134 + the usbi_mutex assertions), including on runs where the BLE work fully succeeded. It is
timing/load dependent in severity but reproduces readily under back-to-back cycles.

Comment thread bumble/transport/usb.py
# device handle, or the context.
logger.debug("waiting for USB event loop to be done...")
await self.event_loop_done
self.event_thread.join()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be done here, because that's a blocking call.
Waiting for the thread to have finished with join should be done on a worker thread, with asyncio.to_thread(). And in that case, we can get rid of setting event_loop_done prior to returning from run. When to_thread returns, the join is known to have completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants