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

Subscribing to SIGINT events etc. handling CTRL+C in terminal #89

Closed
AlexGustafsson opened this issue Apr 10, 2017 · 5 comments
Closed
Assignees

Comments

@AlexGustafsson
Copy link

The code

index.js:

module.exports = botpress => {
...
function gracefulShutdown() {
    console.log('Initiating graceful shutdown');

    broadcast(botpress, 'message')
    .then(() => {
      console.error('Users have been notified. Will now exit');
      process.exit();
    })
    .catch(error => {
      console.error('Could not broadcast message', error);
    });
  }

  // I.e. CTRL+C
  process.on('SIGINT', gracefulShutdown);
  // I.e. kill -p
  process.on('SIGTERM', gracefulShutdown);
  // I.e. keyboard
  process.on('SIGQUIT', gracefulShutdown);
};

The setup

Botpress: latest
Node: v7.7.4
OS: macOS 10.12.4-beta
Other: Using the Terminal app (default macOS command prompt)

The problem

When starting the project with botpress start and then trying to interrupt it with CTRL+C the SIGINT event is correctly thrown. However, the program terminates right after 'Initiating graceful shutdown' has been written to the screen. I've read about a dozen of examples on how to deal with CTRL+C and the code I've written doesn't seem to be wrong. Is there something I should know about how Botpress handles SIGINT, etc.? (I could not find any such event handlers in the source).

Note: debugging shows that broadcast() is never called

@epaminond
Copy link

@AlexGustafsson , where is broadcast coming from? Are you using some package like https://github.com/WebReflection/broadcast?

@AlexGustafsson
Copy link
Author

@epaminond no, it's a function written by me.

// Send a message to all subscribed parties
function broadcast(botpress, message) {
  return botpress.db.kvs.get('subscriptions')
  .then(subscriptions => {
    if (!subscriptions)
      return;
      // ...
  });
}

@epaminond
Copy link

epaminond commented Jun 4, 2018

@AlexGustafsson , I've tried to reproduce it locally with node 8.9.3 and it seems to work fine (e.g. broadcast function gets called and shows console.log statements). node 7.x and 9.x are considered as unstable - could it be an issue? Are you getting same error with node 8.x?

@epaminond
Copy link

@AlexGustafsson , feel free to reopen it if you still face this issue.

@AlexGustafsson
Copy link
Author

@epaminond Thank you for your help. I’ll see if it works for me in the coming days.

@michaelmass michaelmass transferred this issue from botpress/botpress Jun 22, 2023
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

2 participants