Skip to content
This repository
Browse code

Fixed restart race-condition. Closes #125

  • Loading branch information...
commit eed4d3671de1f3b2d287ef21f1f8facbfb87630a 1 parent d55c350
TJ Holowaychuk authored July 19, 2011
12  lib/master.js
@@ -153,6 +153,7 @@ var Master = module.exports = function Master(server) {
153 153
   // spawn our workers
154 154
   this.on('listening', function(){
155 155
     self.spawn(self.options.workers);
  156
+    self.listening = true;
156 157
   });
157 158
 
158 159
   // kill children on master exception
@@ -720,9 +721,16 @@ Master.prototype.spawnMaster = function(){
720 721
 
721 722
 Master.prototype.connectMaster = function(sig){
722 723
   var self = this;
723  
-  this.on('listening', function(){
  724
+
  725
+  function kill(){
724 726
     process.kill(self.ppid, sig);
725  
-  });
  727
+  }
  728
+
  729
+  if (this.listening) {
  730
+    kill();
  731
+  } else {
  732
+    this.on('listening', kill);
  733
+  }
726 734
 };
727 735
 
728 736
 /**
1  test/test.standalone.restart.js
@@ -11,7 +11,6 @@ var assert = require('assert');
11 11
 cluster = cluster()
12 12
   .set('workers', 2)
13 13
   .set('restart threshold', 0)
14  
-  .use(cluster.debug())
15 14
   .start();
16 15
 
17 16
 if (!cluster.isMaster) return;

0 notes on commit eed4d36

Please sign in to comment.
Something went wrong with that request. Please try again.