iohook: process.exit does not work cleanly when iohook is require'd

Expected Behavior

When I call process.exit(0), I expect the process to stop immediately.

Current Behavior

Instead, node hangs altogether for a few seconds, then prints out this error, then node stops:

*** Error in `node': double free or corruption (fasttop): 0x0000000004087470 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7fbb3b38cbfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7fbb3b392fc6]
/lib/x86_64-linux-gnu/libc.so.6(+0x7780e)[0x7fbb3b39380e]
/home/florrie/Documents/splitterm/node_modules/iohook/builds/node-v57-linux-x64/build/Release/iohook.node(_ZNSt5dequeI14_uiohook_eventSaIS0_EE16_M_push_back_auxIIRKS0_EEEvDpOT_+0x13e)[0x7fbb2a5f4e4e]
/home/florrie/Documents/splitterm/node_modules/iohook/builds/node-v57-linux-x64/build/Release/iohook.node(_Z13dispatch_procP14_uiohook_event+0x12c)[0x7fbb2a5f3eac]
/home/florrie/Documents/splitterm/node_modules/iohook/builds/node-v57-linux-x64/build/Release/iohook.node(hook_event_proc+0x4b5)[0x7fbb2a5f55a5]
/usr/lib/x86_64-linux-gnu/libXtst.so.6(+0x19d8)[0x7fbb297099d8]
/usr/lib/x86_64-linux-gnu/libXtst.so.6(XRecordEnableContext+0xf5)[0x7fbb2970ab45]
/home/florrie/Documents/splitterm/node_modules/iohook/builds/node-v57-linux-x64/build/Release/iohook.node(hook_run+0x4f8)[0x7fbb2a5f6748]
/home/florrie/Documents/splitterm/node_modules/iohook/builds/node-v57-linux-x64/build/Release/iohook.node(_Z16hook_thread_procPv+0x9)[0x7fbb2a5f1fb9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7494)[0x7fbb3b6c0494]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7fbb3b404abf]
======= Memory map: ========
(.................)
Aborted

Possible Solution

I’m not sure. I’ve never had much luck dealing with C code alongside node (or at all).

Steps to Reproduce (for bugs)

Here’s a very simple repro case you can run straight from the node REPL:

$ node
> require('iohook')
> process.exit(0)

Just typing .exit instead of process.exit(0) has the same issue, too.

At first I thought the issue only happened after iohook.start(), but this issue happens even if I just require the module. (Obviously, this issue doesn’t happen if I skip require('iohook'), but then I’m not using iohook!)

Context

This issue affects me because I want my code to stop eventually (i.e. after a particular user interaction). Having a ton of garbage be outputted is not helpful.

Your Environment

  • Version used: Latest published version of iohook; ^0.1.15.
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Node v8.2.1.
  • Operating System and version (desktop or mobile): Debian (testing).
  • Link to your project: N/A

Note: Otherwise, iohook does work correctly. I was able to detect a keys being pressed by using ioHook.on('keydown', evt => { ... }).

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Thanks for raising this issue.

I’ll work on implementing this into the project. You could probably work around the issue by putting this snippet into your project.

process.on('exit', () => {
  iohook.unload();
});

Hello guys, I was digging on the issues and code of https://github.com/kwhat/libuiohook and tring to fix another bug I have in my application and found a solution.

He had fixed some errors on related to the latest versions of macOS on this commit:

https://github.com/kwhat/libuiohook/commit/28c99269891d81a764957894f86c7827a0ced3f6

Then I created a manual build to iohook with this version of libuiohook (branch 1.1) and now the app closes with no crash log.

Hi there, could you try to reproduce the error with the current iohook version ? We have updated the libuiohook since and I think it should be fixed.

@towerofnix i’ll try to find a solution for linux on the weekend. 👍