Skip to content
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

call hid_close(libusb/hid.c) stuck on android #595

Open
pengxianheng-nreal opened this issue Jun 29, 2023 · 8 comments
Open

call hid_close(libusb/hid.c) stuck on android #595

pengxianheng-nreal opened this issue Jun 29, 2023 · 8 comments
Labels
Android Android OS related

Comments

@pengxianheng-nreal
Copy link

pengxianheng-nreal commented Jun 29, 2023

as the title show, I use hidapi (libusb/hid.c) to communicate with my usb hid device on android, sometimes, I call hid_close will stuck, It stuck at
hidapi_thread_join(&dev->thread_state);
and when stucking, The "read_thread" thread is running the below loop:

	while (!dev->transfer_loop_finished)
		libusb_handle_events_completed(usb_context, &dev->transfer_loop_finished);

and not jump out。
sometimes, It works fine . In this situation, call hid_close , the read_callback fuction with transfer->status = LIBUSB_TRANSFER_CANCELLE is been called.
But when cause this stuck problem, the read_callback fuction with transfer->status = LIBUSB_TRANSFER_CANCELLE is not been called!

anyone cause the same problem? thanks a lot.

@pengxianheng-nreal pengxianheng-nreal changed the title call hid_close stuck on android call hid_close(libusb/hid.c) stuck on android Jun 29, 2023
@mcuee mcuee added the Android Android OS related label Jun 30, 2023
@mcuee
Copy link
Member

mcuee commented Jun 30, 2023

@pengxianheng-nreal

How do you use hidapi under Android? What is the Android device you use for testing?

Take note there are limitations on how to use hidapi under un-rooted Android devices.

@pengxianheng-nreal
Copy link
Author

pengxianheng-nreal commented Jun 30, 2023

@mcuee The way I use hidapi on android is the same with #178 (comment). use java to get fd, and pass to native hidapi,and call hid_libusb_wrap_sys_device;

@Youw
Copy link
Member

Youw commented Jul 3, 2023

Can you verify that you're not trying to call hid_close concurently with any other HIDAPI function?
Can I assume you're using latest master/latest release of HIDAPI?

@mcuee
Copy link
Member

mcuee commented Aug 14, 2023

@pengxianheng-nreal

Any updates? Thanks.

@pengxianheng-nreal
Copy link
Author

@mcuee I use https://github.com/libusb/hidapi/pull/457/commits to fix my problem. thanks. my code is older than master/latest

@pengxianheng-nreal
Copy link
Author

pengxianheng-nreal commented May 14, 2024

but now,I cause the new cause . even if I use https://github.com/libusb/hidapi/pull/457/commits. also encouter stuck when call hid_close on android. and before stuck , I use hid_write always return -1. and the errno is 9(Bad file descriptor). and after a few seconds usb device has been plugged out. and then I call hid_close stuck . I found it stuck at
hidapi_thread_join(&dev->thread_state); in libusb/hid.c . I don't know why. @mcuee

@pengxianheng-nreal
Copy link
Author

pengxianheng-nreal commented May 14, 2024

Can you verify that you're not trying to call hid_close concurently with any other HIDAPI function? Can I assume you're using latest master/latest release of HIDAPI?

maybe will call hid_write when call hid_close. is this not right calling logic?

@Youw
Copy link
Member

Youw commented May 14, 2024

HIDAPI is not thread-safe.
You definitely shouldn't call both hid_write and hid_close concurently. That is undefined behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android OS related
Projects
None yet
Development

No branches or pull requests

3 participants