-
Notifications
You must be signed in to change notification settings - Fork 123
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
Deadlock when used with NodeJS NAPI module #188
Comments
I am probably never going to be able to reproduce this issue so I will need to rely on you to both provide a solution and test that solution to ensure it works. When you say I need to make a copy of the event, are we talking about the |
We definitely cant comment out those two lines and expect key typed events to work on macOS. It's running into a deadlock because its trying to run that code on the primary runloop and obviously these other languages are using that runloop for something else... Did either of the other solutions mentioned in this ticket work? We should probably figure out why dispatch_sync_f is blocking indefinitely for the main run loop. I suspect node, and probably dart are doing something that blocks the execution on this thread and unfortunately Apple's TIS functions can only be run from that thread. |
I'll look into trying out the other solutions now, but for context, I'm using C++ and I found this issue to still arise in a sandbox like environment. However, since the C demo is working, I'll have to re-check my implementation to ensure it's not an issue on my end. |
I have built the dart wrapper for this library, |
@kwhat I rewrote my implementation of libuiohook and it seems to run perfectly now, tried to keep it quite basic and it seems to have done the trick so for me I have no more issues (I think I must've been doing something dodgy with threading). However, and I'm happy to start another issue if need be, I want to ask if you have had any issues regarding debugging libuiohook on Windows? To reproduce I'm using Visual Studio 2022 on Windows and attached the debugger to the demo_hook example and have hit 'break all' during libuiohook's event loop and it has brought my computer to a standstill. Is this something you've witnessed at all? |
That's good to hear. I have tried to keep as much of the threading out of this library as possible for a number of reasons and as a result of that the event callback always executes on the thread you started to hook from. If you need to do work on the callback, it's probably best to copy the memory to another thread and do the work there. The only other threading happens is on macOS because the TIS function calls have to happen on the main runloop for undocumented reasons from Apple. There are a number of upstream bugs about debugging for windows: #412 #264 #232 and #137. One of these has a possible solution in it where on Windows a debugger attachment can be detected and the hook could be stopped. The same problem should exist on macOS in theory and will also present itself on Linux/Unix as soon as I get the Wayland code in place. I have not tested the proposed solution but if you want to give it a try please open a new bug and we can start with Windows. |
dispatch_sync_f(dispatch_get_main_queue(), XX, XX)
in here line 280 will make a deadlock situation. To resolve this, we need to make a copy of the CGEventRef withCGEventRef eventCopy = CGEventCreateCopy(event);
instead of using a getter from the main thread.related issue: #SnosMe/uiohook-napi#23 (comment)
The call graph is as follows:
The text was updated successfully, but these errors were encountered: