Hotplug: hid_exit() from inside callback should fail fast, not deadlock #795
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi#795
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The hotplug callback documentation added in #790 states:
Rather than rely entirely on documentation, the implementation should detect this case and fail fast (e.g. log an error via the standard error-string path and return without attempting the join) so misuse surfaces as observable errors rather than silent hangs.
Proposed fix
At the start of `hid_exit` (and/or the shared cleanup entrypoint), detect if the current thread is the hotplug thread using `pthread_equal(pthread_self(), hid_hotplug_context.thread)` (or the Windows / IOHID equivalent) and:
This is a defence-in-depth measure layered on top of the documented UB. It overlaps structurally with #794 (macOS self-join in the internal cleanup path); fixing both can share the same "is-self-thread" helper.
Scope
Related
Drafted with Claude Code.