USB HCI transport teardown — usbi_mutex abort on close#963
Open
greateggsgreg wants to merge 1 commit into
Open
USB HCI transport teardown — usbi_mutex abort on close#963greateggsgreg wants to merge 1 commit into
usbi_mutex abort on close#963greateggsgreg wants to merge 1 commit into
Conversation
barbibulle
requested changes
Jul 19, 2026
| # device handle, or the context. | ||
| logger.debug("waiting for USB event loop to be done...") | ||
| await self.event_loop_done | ||
| self.event_thread.join() |
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closing the USB HCI transport (a Nordic nRF52840 Zephyr dongle,
usb:2fe3:000b) abortsUsbPacketSink.terminate()cancels its OUT transfer but reaps it via a shared semaphorethat 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-useReproduce
Run repeated BLE sessions over the nRF USB HCI transport and close each; the abort fires at teardown
(exit 134 + the
usbi_mutexassertions), including on runs where the BLE work fully succeeded. It istiming/load dependent in severity but reproduces readily under back-to-back cycles.