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

Issues shutting down my nodejs application when using this library #5

Closed
magcode opened this issue Dec 28, 2022 · 1 comment
Closed

Comments

@magcode
Copy link

magcode commented Dec 28, 2022

Hello,

I'm playing around with this library.
I want to implement a small application which needs a "proper" shutdown. Unfortunately I don't get it working.
I feel it has something to do with this library...

This is the code:

const ExclusiveKeyboard = require('exclusive-keyboard');

var keyboard = new ExclusiveKeyboard("event6", false);
keyboard.on('error', keyboardError);
keyboard.on('keypress', keydown);
keyboard.on('close', keyboardClose);

function keyboardError(error) {
  console.error("Got keyboard error %s", error)
}

function keyboardClose() {
  console.log("Keyboard closed");
}

function keydown(keyboardEvent) {
  var keyId = keyboardEvent.keyId
  console.log(keyId)
}

function handleExit(signal) {
  console.log(`Received ${signal}. Close my server properly.`)
  keyboard.close();
  keyboard = undefined;
  setTimeout(function () {
    console.log("Will stop now");
    process.exit(0);    
  }, 1000);
}

process.on('SIGINT', handleExit);
process.on('SIGQUIT', handleExit);
process.on('SIGTERM', handleExit);

When you now run the app and hit <ctl+c> it prints:

^CReceived SIGINT. Close my server properly.
Keyboard closed
Will stop now

But it never really stops. I have to kill it using kill -9 <pid>
If I remove handleExit and following code, it works fine.
Any idea what could be the issue here?

@magcode
Copy link
Author

magcode commented Dec 28, 2022

found a workaround similar to lsongdev/input-event#21 (comment)

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

No branches or pull requests

1 participant