song940 / input-event

:musical_keyboard: Read and parse input device(like mouse, keyboard, joystick and IR-Remote)'s event data.

Home Page:https://npmjs.org/input-event

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

new InputEvent() hangs the terminal after closing node, needs kill -9

v934 opened this issue · comments

commented

Hi,
I'm trying to use this package for my nodejs project running on an armv7 device with node v8.9.4.
I was amazed that it worked right away, without any problems. I can easily read events from /dev/input following the examples.

However I have one problem, when I close the node script (ctrl+c), my script itself stops working and I can even catch the SIGINT even telling it to stop, however after pressing ctrl+c, I cannot type anything into the terminal (nor press CTRL+C) anymore, it's stuck. The only way to stop is to execute killall -9 node and it frees the terminal.

It's caused solely by using new InputEvent('/dev/input/event0');, if I comment this line, it's not freezing anymore.

What can be the cause of this? Is there any way to fix it?

Have you try with "/dev/input/by-id/xxx"?

I can confirm this bug(?). Even a process.exit() hangs. Somehow this is caused by the fs.createReadStream() that's not properly cleaned, even though .close() is called in inputEvent.close().

My workaround, sending a SIGTERM to myself on exit:

    process.on('exit', () => {
      // Workaround for the process not terminating on process.exit() due to input-event
      // calling fs.createReadStream() (which, for unknown reason, prevents exit).
      process.kill(process.pid, 'SIGTERM');
    });