wilix-team / iohook

Node.js global keyboard and mouse listener.
https://wilix-team.github.io/iohook
MIT License
1.19k stars 291 forks source link

[OSX] Application crashes due to deallocated memory access #179

Open vadimturkov opened 5 years ago

vadimturkov commented 5 years ago

Periodically our application crashes on OSX with logs info provided below.

Expected Behavior

Work without crashing.

Current Behavior

For example, crash log looks like:

`Crashed Thread: 9

Exception type: EXC_BAD_ACCESS(SIGSEV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000010000000022 Exception Note: EXC_CORPSE_NOTIFY

Thread 9 Crashed: 0 iohook.node 0x0000000110fa359d dispatch_proc(_uiohook_event) + 221 1 iohook.node 0x0000000110fa757d hook_event_proc + 1709 2 com.apple.SkyLight 0x00007fff58f250b4 processDecodedEventRef(__CGEvent, __CGEventTapProxy) + 112 3 com.apple.SkyLight 0x00007fff58f2490d processEventTapData(void, unsigned int, unsigned int, unsigned int, unsigned char, unsigned int) + 543 4 com.apple.SkyLight 0x00007fff58e23bb2 _XPostEventTapData + 278 5 com.apple.SkyLight 0x00007fff58f24690 eventTapMessageHandler(__CFMachPort, void, long, void) + 132 6 com.apple.CoreFoundation 0x00007fff32eb5a5b CFMachPortPerform + 246 7 com.apple.CoreFoundation 0x00007fff32eb5959 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 41 8 com.apple.CoreFoundation 0x00007fff32eb58b7 CFRunLoopDoSource1 + 527 9 com.apple.CoreFoundation 0x00007fff32e9d945 __CFRunLoopRun + 2574 10 com.apple.CoreFoundation 0x00007fff32e9cce4 CFRunLoopRunSpecific + 463 11 com.apple.CoreFoundation 0x00007fff32e9caf0 CFRunLoopRun + 40 12 iohook.node 0x0000000110fa8b74 hook_run + 1700 13 iohook.node 0x0000000110fa365e hook_thread_proc(void*) + 14 14 libsystem_pthread.dylib 0x00007fff6012633d _pthread_body + 126 15 libsystem_pthread.dylib 0x00007fff601292a7 _pthread_start + 70 16 libsystem_pthread.dylib 0x00007fff60125425 thread_start + 13`

Possible Solution

I have no idea. It looks like an access to invalid pointers.

Your Environment

tance77 commented 4 years ago

I have this same issue in my electron app on close. I have since figured out that I had another event that was causing iohooks not to shut down or even start properly in some occasions.

Another thing I had to do was reboot my OSX Application after granting accessibility permissions. I don't even boot iohooks even if the user grants the application permission. I force a re-start of the application. Apple seems to do some weird stuff under the hood with the accessibility permission.

ape-casear commented 3 years ago

maybe the same problem:

on window. electron 5.0.11

Application Specific Information: Assertion Error: Unknown assertion type 0x00000000

Thread 10784 Crashed: 0 iohook.node 0x5bdc1f2b 1 iohook.node 0x5bdc26f2 2 XXX.exe 0x44d2c5f uv_process_async_wakeup_req (async.c:96) 3 XXX.exe 0x34cb1d2 uv_run (core.c:519) 4 XXX.exe 0x34c4e72 atom::NodeBindings::UvRunOnce() (node_bindings.cc:404) 5 XXX.exe 0x29813bb base::debug::TaskAnnotator::RunTask(char const ,base::PendingTask ) (task_annotator.cc:105) 6 XXX.exe 0x29e76d3 base::sequence_manager::internal::ThreadControllerImpl::DoWork(base::sequence_manager::internal::ThreadControllerImpl::WorkType) (thread_controller_impl.cc:209) 7 XXX.exe 0x1510a32 base::internal::Invoker<base::internal::BindState<void (atom::URLRequestFetchJob::*)(int) attribute((thiscall)),base::WeakPtr,net::Error>,void ()>::RunOnce (bind_internal.h:671)

tance77 commented 3 years ago

Following up on this. We also found that the new touch bar on OSX is not supported by iohooks. Which would could similar errors as mentioned above.

michelvermeulen commented 3 years ago

I confirm the touch bar crashed the app every single time.

michelvermeulen commented 3 years ago

I confirm the touch bar crashed the app every single time.

I fixed it by moving iohook to the renderer process

ash0x0 commented 3 years ago

It seems that iohook in main process causes lots of issues on mac specifically. Will investigate but touchbar issue is not something I can address.

fgheorghe commented 2 years ago

Not sure what the status of this issue is, but for me it also crashed if during the lifetime of an Electron app an ioHook event took place. In my case if a mouse drag and mouseup event happened, then when i closed the app it would issue a similar exception. My event handlers are defined in the nodejs main process.

I solved the issue by calling ioHooks.stop(); followed by ioHooks.unload();

Leaving this here in case it helps anyone.

dmatora commented 1 year ago

Solved with

app.on('quit', () => {
  ioHook.unload();
});