-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Crash when calling enumerate from different threads (not simultaneously) #148
Comments
I have a collection of references here:
|
Comments welcome here. |
Interestingly the code does not crash under Windows, with latest cython-hidapi git. |
It also does not crash under Ubuntu 20.04 Linux. I will test under macOS Apple Silicon later on my Mac Mini M1. |
Do you think this is related to the fact hidapi is not thread-safe in general, or it is a specific issue for hidapi under macOS, or cython-hidapi under macOS. Related issues under macOS. |
Oh yes, HIDAPI on macOS has an additional issue regarding thread-safety. I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause. Looks like on macOS I've scheduled for myself (in my Backlog) to look into it, but can't find time for it.
@prusnak could you elaborate the "not simultaneously" part? |
Is this macOS only or on other platforms too? |
not simultaneously = correctly synchronized using a mutex |
And if crash reports/stack traces available - I'll gladly take a look, to figure out if this is HIDAPI issue. |
You can see the stack trace in the original issue where this has been extracted from: bitcoin-core/HWI#659 (comment) |
fixes trezor#142 fixes trezor#148 note trezor#148 (comment) : > HIDAPI on macOS has an additional issue regarding thread-safety. > I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause. > Looks like on macOS hid_init/hid_exit needs to be called in the same thread, > which is an additional restriction compared to other platforms.
Looks like we were not calling |
It was my understanding that hid_init does not need to be called at all, but I guess that's true only for single thread applications. |
It is quite the opposite - it always needs to be called. It is just due to historical reasons (Alan though it is simpler that way) it is called implicitly by hid_enumerate/hid_open. hid_exit is also has to be called when hidapi is no longer in use, to free resources. In some hopeful future we will have an explicit context initialisation, similar way as libusb does it. |
Yes, that's what I meant. So if hid_init is called by hid_enumerate, why does the example above crash? |
see #150 (comment) Line 418 in 8e92053
|
That could the be it, except it crashes inside |
Yes I can reproduce the issue on my Mac Mini M1 running latest macOS Ventura 13.3.1. click for the crash report from macOS on Mac Mini M1
|
With PR #150, the reproducer no longer crashes on my Mac Mini M1. |
fixes #142 fixes #148 note #148 (comment) : > HIDAPI on macOS has an additional issue regarding thread-safety. > I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause. > Looks like on macOS hid_init/hid_exit needs to be called in the same thread, > which is an additional restriction compared to other platforms.
transfered from bitcoin-core/HWI#659
reproducer:
The text was updated successfully, but these errors were encountered: