-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Hanging inside hid_close() #143
Conversation
In case of Maybe there is a race condition which we do not encounter for yet, and we better find and fix it, as even if this patch fixes the behaviour, I think leaving hidden race condition is not a good thing to do in general |
@LudovicRousseau would you mind to take a look at this? Just because you know how libusb works (at least better than me) you might be able to save us some time |
I am not a HIDAPI expert. In fact I do not use this API any more since a few years now. I don't see why adding a new call to Maybe the test in |
You are right, but time to time it is not work. The question is why first call 'libusb_cancel_transfer(dev->transfer);' does not do this? |
libusb_cancel_transfer() - function that asynchronously cancels a transfer. + printf("status[%d]\n", dev->transfer->status); iteration: 209, hid_close() done and so on infinitely... |
One more thing: @vozhyk-com what version/build of LibUSB are you using? Since you're able to reproduce the original issue (I don't have my Linux machine available right now), could you try one more thing? - Enable libusb debug output (in your #142 example): |
hidtest.log.tar.gz I use Debian 10: Package: libusb-1.0-0 |
Closing in favor of #189 |
#142
Function hid_close() waits exit of read_thread().
Thread read_thread() at the end sets
libusb_cancel_transfer(dev->transfer);
and goes to
while (!dev->cancelled)
libusb_handle_events_completed(usb_context, &dev->cancelled);
where libusb calls function read_callback() that should set dev->cancelled to 1.
The problem is: in normal transfer->status should be LIBUSB_TRANSFER_CANCELLED,
but time to time it is LIBUSB_TRANSFER_COMPLETED, I do not know why.
in that case dev->cancelled never set to 1 and we hang in a while().