Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed `cli()` hang regression. Closes #148

  • Loading branch information...
commit 292a4b05097129d78a6e13f2b375195d7eeaaf60 1 parent c7b8855
@tj tj authored
Showing with 24 additions and 14 deletions.
  1. +24 −14 lib/master.js
View
38 lib/master.js
@@ -128,17 +128,6 @@ var Master = module.exports = function Master(server) {
// custom worker fds, defaults to std{out,err}
this.customFds = [1, 2];
- // udp server for IPC
- this._server = dgram.createSocket('udp4');
- this._server.on('message', function(msg, info){
- try {
- msg = JSON.parse(msg.toString('ascii'));
- self.invoke(msg.method, msg.args, self.children[msg.id]);
- } catch (err) {
- console.error(err.stack || String(err));
- }
- });
-
// resolve server filename
if (this.isWorker && 'string' == typeof this.server) {
this.server = require(this.resolve(this.server));
@@ -303,6 +292,27 @@ Master.prototype.listen = function(port, host, callback){
};
/**
+ * Create / return IPC socket.
+ *
+ * @api private
+ */
+
+Master.prototype.IPCSocket = function(){
+ var self = this;
+ if (this._sock) return this._sock;
+ this._sock = dgram.createSocket('udp4');
+ this._sock.on('message', function(msg, info){
+ try {
+ msg = JSON.parse(msg.toString('ascii'));
+ self.invoke(msg.method, msg.args, self.children[msg.id]);
+ } catch (err) {
+ console.error(err.stack || String(err));
+ }
+ });
+ return this._sock;
+};
+
+/**
* Setup IPC.
*
* @api private
@@ -318,14 +328,14 @@ Master.prototype.setupIPC = function(){
this.defaultWorkers();
// udp server for IPC
- this._server.on('listening', function(){
+ this.IPCSocket().on('listening', function(){
process.nextTick(function(){
self.emit('start');
});
});
// bind
- this._server.bind(
+ this.IPCSocket().bind(
this.options['socket port']
, this.options['socket addr']);
};
@@ -763,7 +773,7 @@ Master.prototype.acceptFd = function(){
*/
Master.prototype._destroy = function(){
- this._server.close();
+ this.IPCSocket().close();
if (this.fd) close(this.fd);
this.emit('close');
process.nextTick(process.exit.bind(process));
Please sign in to comment.
Something went wrong with that request. Please try again.