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

Crash when calling enumerate from different threads (not simultaneously) #148

Closed
prusnak opened this issue Feb 13, 2023 · 19 comments · Fixed by #150
Closed

Crash when calling enumerate from different threads (not simultaneously) #148

prusnak opened this issue Feb 13, 2023 · 19 comments · Fixed by #150

Comments

@prusnak
Copy link
Member

prusnak commented Feb 13, 2023

transfered from bitcoin-core/HWI#659

reproducer:

import hid
import threading

def e():
    m.acquire()
    print(hid.enumerate())
    m.release()

m = threading.Lock()

a = threading.Thread(target=e, args=())
b = threading.Thread(target=e, args=())
c = threading.Thread(target=e, args=())

a.start()
b.start()
c.start()

a.join()
b.join()
c.join()
@SomberNight
Copy link
Contributor

AFAIk hidapi is not thread-safe on neither of supported platforms

Hm, I might be wrong. I only found this 11 years old comment: signal11/hidapi#56 (comment)

I have a collection of references here:
https://github.com/spesmilo/electrum/blob/33d394c9d76acceeffaa3adb032e51bed38dfe87/electrum/plugin.py#L331-L335

hidapi is not thread-safe
see signal11/hidapi#205 (comment)
libusb/hidapi#45
signal11/hidapi#45 (comment)
signal11/hidapi#414 (comment)

@mcuee
Copy link

mcuee commented May 10, 2023

Comments welcome here.

@mcuee
Copy link

mcuee commented May 10, 2023

Interestingly the code does not crash under Windows, with latest cython-hidapi git.

@mcuee
Copy link

mcuee commented May 10, 2023

It also does not crash under Ubuntu 20.04 Linux.

I will test under macOS Apple Silicon later on my Mac Mini M1.

@mcuee
Copy link

mcuee commented May 10, 2023

@Youw

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.

@Youw
Copy link
Contributor

Youw commented May 10, 2023

it is a specific issue for hidapi 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 hid_init/hid_exit needs to be called in the same thread, which is an additional restriction compared to other platforms.

I've scheduled for myself (in my Backlog) to look into it, but can't find time for it.

from different threads (not simultaneously)

@prusnak could you elaborate the "not simultaneously" part?
I'm not exactly aware how the python threading + cython-hidapi (+ GIL?) all work out together.

@Youw
Copy link
Contributor

Youw commented May 10, 2023

Crash when calling enumerate

Is this macOS only or on other platforms too?

@prusnak
Copy link
Member Author

prusnak commented May 10, 2023

could you elaborate the "not simultaneously" part?

not simultaneously = correctly synchronized using a mutex

@Youw
Copy link
Contributor

Youw commented May 10, 2023

And if crash reports/stack traces available - I'll gladly take a look, to figure out if this is HIDAPI issue.

@prusnak
Copy link
Member Author

prusnak commented May 10, 2023

And if crash reports/stack traces available

You can see the stack trace in the original issue where this has been extracted from: bitcoin-core/HWI#659 (comment)

SomberNight added a commit to SomberNight/cython-hidapi that referenced this issue May 10, 2023
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.
@SomberNight
Copy link
Contributor

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 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 hid_init at all.
And, ah, that seems to fix both issues >.<
see #150

@prusnak
Copy link
Member Author

prusnak commented May 10, 2023

Looks like we were not calling hid_init at all.

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.

@Youw
Copy link
Contributor

Youw commented May 10, 2023

hid_init does not need to be called at all

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.

@prusnak
Copy link
Member Author

prusnak commented May 10, 2023

t is called implicitly by hid_enumerate/hid_open.

Yes, that's what I meant.

So if hid_init is called by hid_enumerate, why does the example above crash?

@SomberNight
Copy link
Contributor

So if hid_init is called by hid_enumerate, why does the example above crash?

see #150 (comment)
because hid_exit is called on the main thread, which is not where hid_enumerate runs:

weakref.finalize(sys.modules[__name__], hid_exit)

@Youw
Copy link
Contributor

Youw commented May 10, 2023

That bugs me as well. As I said - I do not know how python multithreading works on low-level. We actually seen some similar issues on macos when used with Golang and we couldn't find out the root cause there as well (even though found a workaround).

@Youw
Copy link
Contributor

Youw commented May 10, 2023

because hid_exit is called on the main thread

That could the be it, except it crashes inside hid_enumerate (as per stacktrace), not inside hid_exit as I've had suspect originally.

@mcuee
Copy link

mcuee commented May 11, 2023

I will test under macOS Apple Silicon later on my Mac Mini M1.

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
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Python [4483]
Path:                  /opt/homebrew/*/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python
Identifier:            org.python.python
Version:               3.9.16 (3.9.16)
Code Type:             ARM-64 (Native)
Parent Process:        zsh [1017]
Responsible:           Terminal [1014]
User ID:               501

Date/Time:             2023-05-11 08:24:10.9108 +0800
OS Version:            macOS 13.3.1 (22E261)
Report Version:        12
Anonymous UUID:        42E4176B-6AC7-D4CA-E9DC-A4B9DEA90EE3


Time Awake Since Boot: 420 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x000000019f57bc54

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [4483]

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   CoreFoundation                	       0x19f57bc54 _CFAssertMismatchedTypeID + 112
1   CoreFoundation                	       0x19f438be0 CFRunLoopRemoveSource + 704
2   IOKit                         	       0x1a24feef8 IOHIDDeviceUnscheduleFromRunLoop + 140
3   IOKit                         	       0x1a2503dc0 __IOHIDManagerDeviceApplier + 660
4   CoreFoundation                	       0x19f3dfbcc __CFSetApplyFunction_block_invoke + 28
5   CoreFoundation                	       0x19f3df9e4 CFBasicHashApply + 148
6   CoreFoundation                	       0x19f3df928 CFSetApplyFunction + 320
7   IOKit                         	       0x1a250249c __ApplyToDevices + 128
8   IOKit                         	       0x1a25025d8 IOHIDManagerUnscheduleFromRunLoop + 112
9   IOKit                         	       0x1a25024fc IOHIDManagerClose + 44
10  hid.cpython-39-darwin.so      	       0x102fcf3b0 hid_exit + 32
11  hid.cpython-39-darwin.so      	       0x102fcf19c __pyx_pw_11cfunc_dot_to_py_27__Pyx_CFunc_int_______to_py_1wrap + 24
12  Python                        	       0x10309d3dc _PyObject_Call + 128
13  Python                        	       0x103188d30 _PyEval_EvalFrameDefault + 2396
14  Python                        	       0x1031873d4 _PyEval_EvalCode + 452
15  Python                        	       0x10309d638 _PyFunction_Vectorcall + 344
16  Python                        	       0x10309cccc _PyObject_FastCallDictTstate + 96
17  Python                        	       0x10310f644 slot_tp_call + 188
18  Python                        	       0x10309ca4c _PyObject_MakeTpCall + 132
19  Python                        	       0x103194498 call_function + 268
20  Python                        	       0x10318c5bc _PyEval_EvalFrameDefault + 16872
21  Python                        	       0x10309d598 _PyFunction_Vectorcall + 184
22  Python                        	       0x1030a0118 method_vectorcall + 388
23  Python                        	       0x1032462a4 atexit_callfuncs + 124
24  Python                        	       0x1031d55f8 Py_FinalizeEx + 892
25  Python                        	       0x1031fba4c Py_RunMain + 428
26  Python                        	       0x1031fd0e0 Py_BytesMain + 40
27  dyld                          	       0x19efdff28 start + 2236

Thread 1:
0   libsystem_pthread.dylib       	       0x19f332d8c start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib       	       0x19f332d8c start_wqthread + 0


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x000000000000004a   x1: 0x000000019f724e41   x2: 0x0000000000000000   x3: 0x000000016d16e50b
    x4: 0x0000000000000000   x5: 0x000000016d16e4a0   x6: 0x0000000000000029   x7: 0x000000016d16ecd8
    x8: 0x00000001facb5000   x9: 0xfa6b9b090a4e008c  x10: 0x0000000000000200  x11: 0x000000016d16e010
   x12: 0x000000000000000a  x13: 0x000000013bf43860  x14: 0xffffffffffffffff  x15: 0x00000000c60aa7fb
   x16: 0x000000019f159c44  x17: 0x00000001ff2c17d8  x18: 0x0000000000000000  x19: 0x000000016d16e4c1
   x20: 0x000000000000002b  x21: 0x000000019f71aeac  x22: 0x000000019f723e0c  x23: 0x0000000000000000
   x24: 0x000000013bf43920  x25: 0x0000000102f92900  x26: 0x0000000102ee8930  x27: 0x000000013bf04e20
   x28: 0x0000000102f11c50   fp: 0x000000016d16e5f0   lr: 0x956480019f57bc4c
    sp: 0x000000016d16e4a0   pc: 0x000000019f57bc54 cpsr: 0x60001000
   far: 0x000000012c00c03d  esr: 0xf2000001 (Breakpoint) brk 1

Binary Images:
       0x102c90000 -        0x102c93fff org.python.python (3.9.16) <9afd964b-c386-32f8-9d4e-89c8e14bb5fa> /opt/homebrew/*/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python
       0x103044000 -        0x1032fffff org.python.python (3.9.16, (c) 2001-2021 Python Software Foundation.) <7397b7d9-a63d-3cea-af3d-c47e9ebde96f> /opt/homebrew/*/Python.framework/Versions/3.9/Python
       0x102f4c000 -        0x102f4ffff _heapq.cpython-39-darwin.so (*) <da1e04e9-9704-3aad-9736-dde3041b0e69> /opt/homebrew/*/Python.framework/Versions/3.9/lib/python3.9/lib-dynload/_heapq.cpython-39-darwin.so
       0x102fc4000 -        0x102fd3fff hid.cpython-39-darwin.so (*) <243b4adb-97f6-3373-ae6b-e60dcb1b0f65> /Users/USER/*/hid.cpython-39-darwin.so
       0x103424000 -        0x10343bfff com.apple.iokit.IOHIDLib (2.0.0) <3f1e2f79-4c68-30b9-92ba-2db9304018d3> /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib
       0x19f397000 -        0x19f870fff com.apple.CoreFoundation (6.9) <b4fdaece-9727-3969-b014-27f7f24c8e01> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
       0x1a24bb000 -        0x1a2595fff com.apple.framework.IOKit (2.0.2) <e0c7b0e8-73c8-345c-b2c0-f0f62b477163> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
       0x19efda000 -        0x19f06853b dyld (*) <ac277a36-1808-327a-8761-cca585421212> /usr/lib/dyld
       0x19f331000 -        0x19f33dfff libsystem_pthread.dylib (*) <b401cfb3-8dfe-32db-92b3-ba8af0f8ca6e> /usr/lib/system/libsystem_pthread.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=1.0G resident=0K(0%) swapped_out_or_unallocated=1.0G(100%)
Writable regions: Total=833.1M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=833.1M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Activity Tracing                   256K        1 
Kernel Alloc Once                   32K        1 
MALLOC                           189.2M       21 
MALLOC guard page                   96K        5 
MALLOC_MEDIUM (reserved)         240.0M        2         reserved VM address space (unallocated)
MALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)
STACK GUARD                         48K        3 
Stack                             17.1M        3 
VM_ALLOCATE                       2304K        9 
__AUTH                             575K      132 
__AUTH_CONST                      11.1M      270 
__DATA                            2963K      261 
__DATA_CONST                      13.9M      276 
__DATA_DIRTY                       678K       97 
__FONT_DATA                        2352        1 
__LINKEDIT                       801.0M        6 
__OBJC_RO                         66.2M        1 
__OBJC_RW                         2011K        1 
__TEXT                           214.4M      288 
dyld private memory                272K        2 
mapped file                         64K        1 
shared memory                       32K        2 
===========                     =======  ======= 
TOTAL                              1.9G     1384 
TOTAL, minus reserved VM space     1.3G     1384 



-----------
Full Report
-----------

{"app_name":"Python","timestamp":"2023-05-11 08:24:13.00 +0800","app_version":"3.9.16","slice_uuid":"9afd964b-c386-32f8-9d4e-89c8e14bb5fa","build_version":"3.9.16","platform":1,"bundleID":"org.python.python","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 13.3.1 (22E261)","roots_installed":0,"name":"Python","incident_id":"D5DAA6AB-A021-4FFC-9145-4ED0EE6DF5E5"}
{
  "uptime" : 420,
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "Macmini9,1",
  "coalitionID" : 923,
  "osVersion" : {
    "train" : "macOS 13.3.1",
    "build" : "22E261",
    "releaseType" : "User"
  },
  "captureTime" : "2023-05-11 08:24:10.9108 +0800",
  "incident" : "D5DAA6AB-A021-4FFC-9145-4ED0EE6DF5E5",
  "pid" : 4483,
  "translated" : false,
  "cpuType" : "ARM-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2023-05-11 08:24:10.3539 +0800",
  "procStartAbsTime" : 10185790812,
  "procExitAbsTime" : 10199114221,
  "procName" : "Python",
  "procPath" : "\/opt\/homebrew\/*\/Python.framework\/Versions\/3.9\/Resources\/Python.app\/Contents\/MacOS\/Python",
  "bundleInfo" : {"CFBundleShortVersionString":"3.9.16","CFBundleVersion":"3.9.16","CFBundleIdentifier":"org.python.python"},
  "storeInfo" : {"deviceIdentifierForVendor":"788BDE95-76C9-54B0-A2CF-D591CE74858E","thirdParty":true},
  "parentProc" : "zsh",
  "parentPid" : 1017,
  "coalitionName" : "com.apple.Terminal",
  "crashReporterKey" : "42E4176B-6AC7-D4CA-E9DC-A4B9DEA90EE3",
  "responsiblePid" : 1014,
  "responsibleProc" : "Terminal",
  "codeSigningID" : "org.python.python",
  "codeSigningTeamID" : "",
  "codeSigningFlags" : 570425857,
  "codeSigningValidationCategory" : 10,
  "codeSigningTrustLevel" : 0,
  "sip" : "enabled",
  "exception" : {"codes":"0x0000000000000001, 0x000000019f57bc54","rawCodes":[1,6968294484],"type":"EXC_BREAKPOINT","signal":"SIGTRAP"},
  "termination" : {"flags":0,"code":5,"namespace":"SIGNAL","indicator":"Trace\/BPT trap: 5","byProc":"exc handler","byPid":4483},
  "os_fault" : {"process":"Python"},
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":19452,"threadState":{"x":[{"value":74},{"value":6970035777,"symbolLocation":7405,"symbol":"_XMLPlistAppendDataUsingBase64.__CFPLDataEncodeTable"},{"value":0},{"value":6125184267},{"value":0},{"value":6125184160},{"value":41},{"value":6125186264},{"value":8502595584,"symbolLocation":6792,"symbol":"__last_exception_backtrace__"},{"value":18044686795119919244},{"value":512},{"value":6125182992},{"value":10},{"value":5300828256},{"value":18446744073709551615},{"value":3322587131},{"value":6963960900,"symbolLocation":0,"symbol":"free"},{"value":8576047064},{"value":0},{"value":6125184193},{"value":43},{"value":6969994924},{"value":6970031628,"symbolLocation":3256,"symbol":"_XMLPlistAppendDataUsingBase64.__CFPLDataEncodeTable"},{"value":0},{"value":5300828448},{"value":4344850688},{"value":4344154416},{"value":5300571680},{"value":4344323152}],"flavor":"ARM_THREAD_STATE64","lr":{"value":10764869753778977868},"cpsr":{"value":1610616832},"fp":{"value":6125184496},"sp":{"value":6125184160},"esr":{"value":4060086273,"description":"(Breakpoint) brk 1"},"pc":{"value":6968294484,"matchesCrashFrame":1},"far":{"value":5033214013}},"queue":"com.apple.main-thread","frames":[{"imageOffset":1985620,"symbol":"_CFAssertMismatchedTypeID","symbolLocation":112,"imageIndex":5},{"imageOffset":662496,"symbol":"CFRunLoopRemoveSource","symbolLocation":704,"imageIndex":5},{"imageOffset":278264,"symbol":"IOHIDDeviceUnscheduleFromRunLoop","symbolLocation":140,"imageIndex":6},{"imageOffset":298432,"symbol":"__IOHIDManagerDeviceApplier","symbolLocation":660,"imageIndex":6},{"imageOffset":297932,"symbol":"__CFSetApplyFunction_block_invoke","symbolLocation":28,"imageIndex":5},{"imageOffset":297444,"symbol":"CFBasicHashApply","symbolLocation":148,"imageIndex":5},{"imageOffset":297256,"symbol":"CFSetApplyFunction","symbolLocation":320,"imageIndex":5},{"imageOffset":291996,"symbol":"__ApplyToDevices","symbolLocation":128,"imageIndex":6},{"imageOffset":292312,"symbol":"IOHIDManagerUnscheduleFromRunLoop","symbolLocation":112,"imageIndex":6},{"imageOffset":292092,"symbol":"IOHIDManagerClose","symbolLocation":44,"imageIndex":6},{"imageOffset":46000,"symbol":"hid_exit","symbolLocation":32,"imageIndex":3},{"imageOffset":45468,"symbol":"__pyx_pw_11cfunc_dot_to_py_27__Pyx_CFunc_int_______to_py_1wrap","symbolLocation":24,"imageIndex":3},{"imageOffset":365532,"symbol":"_PyObject_Call","symbolLocation":128,"imageIndex":1},{"imageOffset":1330480,"symbol":"_PyEval_EvalFrameDefault","symbolLocation":2396,"imageIndex":1},{"imageOffset":1323988,"symbol":"_PyEval_EvalCode","symbolLocation":452,"imageIndex":1},{"imageOffset":366136,"symbol":"_PyFunction_Vectorcall","symbolLocation":344,"imageIndex":1},{"imageOffset":363724,"symbol":"_PyObject_FastCallDictTstate","symbolLocation":96,"imageIndex":1},{"imageOffset":833092,"symbol":"slot_tp_call","symbolLocation":188,"imageIndex":1},{"imageOffset":363084,"symbol":"_PyObject_MakeTpCall","symbolLocation":132,"imageIndex":1},{"imageOffset":1377432,"symbol":"call_function","symbolLocation":268,"imageIndex":1},{"imageOffset":1344956,"symbol":"_PyEval_EvalFrameDefault","symbolLocation":16872,"imageIndex":1},{"imageOffset":365976,"symbol":"_PyFunction_Vectorcall","symbolLocation":184,"imageIndex":1},{"imageOffset":377112,"symbol":"method_vectorcall","symbolLocation":388,"imageIndex":1},{"imageOffset":2106020,"symbol":"atexit_callfuncs","symbolLocation":124,"imageIndex":1},{"imageOffset":1644024,"symbol":"Py_FinalizeEx","symbolLocation":892,"imageIndex":1},{"imageOffset":1800780,"symbol":"Py_RunMain","symbolLocation":428,"imageIndex":1},{"imageOffset":1806560,"symbol":"Py_BytesMain","symbolLocation":40,"imageIndex":1},{"imageOffset":24360,"symbol":"start","symbolLocation":2236,"imageIndex":7}]},{"id":19468,"frames":[{"imageOffset":7564,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":8}]},{"id":19469,"frames":[{"imageOffset":7564,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":8}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4341694464,
    "CFBundleShortVersionString" : "3.9.16",
    "CFBundleIdentifier" : "org.python.python",
    "size" : 16384,
    "uuid" : "9afd964b-c386-32f8-9d4e-89c8e14bb5fa",
    "path" : "\/opt\/homebrew\/*\/Python.framework\/Versions\/3.9\/Resources\/Python.app\/Contents\/MacOS\/Python",
    "name" : "Python",
    "CFBundleVersion" : "3.9.16"
  },
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4345577472,
    "CFBundleShortVersionString" : "3.9.16, (c) 2001-2021 Python Software Foundation.",
    "CFBundleIdentifier" : "org.python.python",
    "size" : 2867200,
    "uuid" : "7397b7d9-a63d-3cea-af3d-c47e9ebde96f",
    "path" : "\/opt\/homebrew\/*\/Python.framework\/Versions\/3.9\/Python",
    "name" : "Python",
    "CFBundleVersion" : "3.9.16"
  },
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4344561664,
    "size" : 16384,
    "uuid" : "da1e04e9-9704-3aad-9736-dde3041b0e69",
    "path" : "\/opt\/homebrew\/*\/Python.framework\/Versions\/3.9\/lib\/python3.9\/lib-dynload\/_heapq.cpython-39-darwin.so",
    "name" : "_heapq.cpython-39-darwin.so"
  },
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4345053184,
    "size" : 65536,
    "uuid" : "243b4adb-97f6-3373-ae6b-e60dcb1b0f65",
    "path" : "\/Users\/USER\/*\/hid.cpython-39-darwin.so",
    "name" : "hid.cpython-39-darwin.so"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 4349640704,
    "CFBundleShortVersionString" : "2.0.0",
    "CFBundleIdentifier" : "com.apple.iokit.IOHIDLib",
    "size" : 98304,
    "uuid" : "3f1e2f79-4c68-30b9-92ba-2db9304018d3",
    "path" : "\/System\/Library\/Extensions\/IOHIDFamily.kext\/Contents\/PlugIns\/IOHIDLib.plugin\/Contents\/MacOS\/IOHIDLib",
    "name" : "IOHIDLib",
    "CFBundleVersion" : "2.0.0"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6966308864,
    "CFBundleShortVersionString" : "6.9",
    "CFBundleIdentifier" : "com.apple.CoreFoundation",
    "size" : 5087232,
    "uuid" : "b4fdaece-9727-3969-b014-27f7f24c8e01",
    "path" : "\/System\/Library\/Frameworks\/CoreFoundation.framework\/Versions\/A\/CoreFoundation",
    "name" : "CoreFoundation",
    "CFBundleVersion" : "1971"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 7017836544,
    "CFBundleShortVersionString" : "2.0.2",
    "CFBundleIdentifier" : "com.apple.framework.IOKit",
    "size" : 897024,
    "uuid" : "e0c7b0e8-73c8-345c-b2c0-f0f62b477163",
    "path" : "\/System\/Library\/Frameworks\/IOKit.framework\/Versions\/A\/IOKit",
    "name" : "IOKit"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6962388992,
    "size" : 582972,
    "uuid" : "ac277a36-1808-327a-8761-cca585421212",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6965891072,
    "size" : 53248,
    "uuid" : "b401cfb3-8dfe-32db-92b3-ba8af0f8ca6e",
    "path" : "\/usr\/lib\/system\/libsystem_pthread.dylib",
    "name" : "libsystem_pthread.dylib"
  }
],
  "sharedCache" : {
  "base" : 6961725440,
  "size" : 3539533824,
  "uuid" : "ebddd61c-5dcf-399c-a88b-759edf197103"
},
...
...

@mcuee
Copy link

mcuee commented May 11, 2023

With PR #150, the reproducer no longer crashes on my Mac Mini M1.

prusnak pushed a commit that referenced this issue May 11, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants