SomeKittens SomeKittens - 1 year ago 133
Javascript Question

How do I get SocketCluster to restart on file change?

I'm running 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?

Answer Source

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){

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

forever -w --killSignal=SIGTERM server.js
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download