1

I'm running http://socketcluster.io/ and I want to restart my workers whewnever a file changes. However, nodemon server.js fails as soon as it tries to restart with an endlessly-repeating wall of:

1445633138359 - Origin: Worker (PID 44372)
    [Error] Error: connect ECONNREFUSED /var/folders/fj/yzfd3_tn7xd0smz7j6s093mh0000gn/T/socketcluster/6879fe94-ed92-4188-b1d7-cb187a5ade4e_b68fcded6c/b0
    at Object.exports._errnoException (util.js:874:11)
    at exports._exceptionWithHostPort (util.js:897:20)
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
1445633138362 - Worker 0 exited - Exit code: 0

How can I safely restart SocketCluster to load the new changes?

SomeKittens
  • 38,868
  • 19
  • 114
  • 143

2 Answers2

2

nodemon sends the SIGUSR2 signal to the main (Master) process. SocketCluster (correctly) interprets this as as a request to reboot the workers. Unfortunately, there's an open issue where things are not shut down properly and errors fly all around.

There are two options:

You can add the code from the linked issue:

house.addShutdownHandler(function(ctx, next){
    socketCluster.killWorkers();
    socketCluster.killBrokers();
    next();
});

or use forever to send a "restart everything" signal:

forever -w --killSignal=SIGTERM server.js
SomeKittens
  • 38,868
  • 19
  • 114
  • 143
  • Hi .. where exactly would one implement this? is this a patch i'd need to specify in the sc code itself? I'm confused over the `house` variable used – Jayaram Aug 24 '16 at 06:19
0

Improvements were made for nodemon in SC version 5.0.23 or later.

Make sure that you pass killMasterOnSignal: true when instantiating SocketCluster in your code (server.js file) - This setting is necessary for nodemon to work.

Jon
  • 1,224
  • 2
  • 14
  • 23