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

Expose redis quit function #8

Closed
Joshua-Anderson opened this issue Apr 26, 2014 · 1 comment
Closed

Expose redis quit function #8

Joshua-Anderson opened this issue Apr 26, 2014 · 1 comment

Comments

@Joshua-Anderson
Copy link

I use socket.io-redis with my node js cluster app. Instead of just exiting on SIGTERM and SIGINT, I gracefully exit and close all connections. However, using the socket.io-redis my child processes never exit, problaby redis connection is persisted, leaving a dead process that has to be forced killed using kill -9. Here is a quick reproduction script:

cluster = require('cluster');

if (cluster.isMaster) {
  cluster.fork();
  process.on('SIGTERM', gracefulMasterExit).on('SIGINT', gracefulMasterExit);

  process.on('exit', function () {
    console.log("Successfully shut down");
  });

  function gracefulMasterExit() {
      console.log("Got SIGINT or SIGTERM, gracefully exiting");
  }

} else {
  var server = require('http').Server();
  var io = require('socket.io')(server);
  io.adapter(require('socket.io-redis')('localhost:6379'));
  server.listen(3000);

  process.on('SIGTERM', gracefulExit).on('SIGINT', gracefulExit);

  function gracefulExit() {
      console.log("Worker " + cluster.worker.process.pid + " exiting gracefully");
      cluster.worker.disconnect();
  }
}

After running this you should see Worker <PID> exiting gracefully, but if you look at your process manager you will still see that worker running with the master process dead. In this particular case sending SIGTERM or SIGINT will trigger a channel closed error but in my actual code the program will just return leaving the worker running in the background. Commenting out the redis adapter line will resolve the problem.

Thanks for taking a look at this!

@rauchg
Copy link
Contributor

rauchg commented Apr 30, 2014

For "advanced usecases" like this is that we accept a redis instance that you can control and call methods on:
https://github.com/Automattic/socket.io-redis#adapteropts

Thanks for the thorough explanation though, I really appreciate it.

@rauchg rauchg closed this as completed Apr 30, 2014
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