Linux: Hanging inside hid_close() #142
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#142
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?
For catching this hanging need just open device by hid_open() or hid_open_path() and close it by hid_close(), see simple example:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "hidapi.h"
int main(int argc, char* argv[])
{
hid_device *handle;
struct hid_device_info *devs, *cur_dev;
}
I wasn't able to reproduce the original issue, presumably because I don't have a device that would allow me to do so.
I believe there is a race condition, that when hit, may lead to deadlock, when trying to close the device, in case if device submits transfers/interruptions frequently, and device is being closed exactly during successful handling of such transfer.
The fix suggested in #143 kind-of fixes the issue. Kind-of, because it constantly tries not to hit a deadlock, but a race condition is still there, it is a root cause, and we better fix a root cause, not symptoms.
@vozhyk-com would you be able to check a patch I prepared, with your device? https://github.com/libusb/hidapi/tree/libusb-hang
I confirm that the patch from branch libusb-hang solves #142 issue. I can not reproduce it with the patch, but easy can reproduce without.
That's awesome news. As I hoped, the root issue found and fixed.