Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow reload plugin to continue restarting master after syntax errors are fixed. #137

Open
wants to merge 2 commits into from

1 participant

@jdeal

The reload plugin gets stuck if there's a syntax error. The master can't re-spawn since there's a syntax error, and the reload plugin won't try again, because the restarting flag gets set to true. This fork watches for the master process to exit and then emits an 'exit' event for the master. This way, the reload plugin can watch for the 'exit' event and reset its restarting flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 2 deletions.
  1. +1 −1  examples/reload.js
  2. +7 −0 lib/master.js
  3. +6 −1 lib/plugins/reload.js
View
2  examples/reload.js
@@ -21,4 +21,4 @@ cluster(server)
.set('workers', 1)
.use(cluster.reload())
.use(cluster.debug())
- .listen(3000);
+ .listen(3000);
View
7 lib/master.js
@@ -67,6 +67,7 @@ var node = process.execPath;
* which can be patched in order to preserve plugin state.
* - `restart`. Restart complete, new master established, previous died.
* Receives an object with state preserved by the `restarting` event.
+ * - `exit`. When a restarted master process exits.
*
* Signals:
*
@@ -684,6 +685,12 @@ Master.prototype.spawnMaster = function(){
customFds: customFds
, env: env
});
+
+ // watch for exit in case of problem during restart
+ var self = this;
+ proc.on('exit',function(){
+ self.emit('exit',{});
+ });
// unix domain socket for ICP + fd passing
proc.sock = new net.Socket(fds[1], 'unix');
View
7 lib/plugins/reload.js
@@ -115,6 +115,11 @@ exports = module.exports = function(files, options){
master.on('restarting', function(){
restarting = true;
});
+
+ master.on('exit', function(){
+ // must have been a problem
+ restarting = false;
+ });
}
};
@@ -122,4 +127,4 @@ exports = module.exports = function(files, options){
* Directories to ignore.
*/
-exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin'];
+exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin'];
Something went wrong with that request. Please try again.