diff --git a/lib/connectors/commands/heartbeat.js b/lib/connectors/commands/heartbeat.js index 213ce4efc..3c8b69470 100644 --- a/lib/connectors/commands/heartbeat.js +++ b/lib/connectors/commands/heartbeat.js @@ -34,15 +34,15 @@ Command.prototype.handle = function(socket) { var self = this; if(!this.clients[socket.id]) { - // clear timers when socket disconnect or error + // clear client and timer when socket disconnect or error this.clients[socket.id] = 1; - socket.once('disconnect', clearTimers.bind(null, this, socket.id)); - socket.once('error', clearTimers.bind(null, this, socket.id)); + socket.once('disconnect', this.clear.bind(this, socket.id)); + socket.once('error', this.clear.bind(this, socket.id)); } // clear timeout timer if(self.disconnectOnTimeout) { - this.clear(socket.id); + this.clearTimers(socket.id); } socket.sendRaw(Package.encode(Package.TYPE_HEARTBEAT)); @@ -55,7 +55,7 @@ Command.prototype.handle = function(socket) { } }; -Command.prototype.clear = function(id) { +Command.prototype.clearTimers = function(id) { var tid = this.timeouts[id]; if(tid) { clearTimeout(tid); @@ -63,11 +63,11 @@ Command.prototype.clear = function(id) { } }; -var clearTimers = function(self, id) { - delete self.clients[id]; - var tid = self.timeouts[id]; +Command.prototype.clear = function(id) { + delete this.clients[id]; + var tid = this.timeouts[id]; if(tid) { clearTimeout(tid); - delete self.timeouts[id]; + delete this.timeouts[id]; } }; diff --git a/lib/connectors/udpsocket.js b/lib/connectors/udpsocket.js index 769f5ae8c..022038bef 100644 --- a/lib/connectors/udpsocket.js +++ b/lib/connectors/udpsocket.js @@ -11,16 +11,14 @@ var ST_WORKING = 2; var ST_CLOSED = 3; var Socket = function(id, socket, peer) { - EventEmitter.call(this); - + EventEmitter.call(this); + this.id = id; - this.socket = socket; + this.socket = socket; this.peer = peer; - this.host = peer.address; - this.port = peer.port; - this.remoteAddress = { - ip: this.host, - port: this.port + this.remoteAddress = { + ip: this.peer.address, + port: this.peer.port }; var self = this; @@ -56,7 +54,7 @@ Socket.prototype.send = function(msg) { }; Socket.prototype.sendRaw = function(msg) { - this.socket.send(msg, 0, msg.length, this.port, this.host, function(err, bytes) { + this.socket.send(msg, 0, msg.length, this.remoteAddress.port, this.remoteAddress.ip, function(err, bytes) { if(!!err) { logger.error('send msg to remote with err: %j', err.stack); return; diff --git a/lib/modules/console.js b/lib/modules/console.js index 19a13aa51..78f0dd56a 100644 --- a/lib/modules/console.js +++ b/lib/modules/console.js @@ -117,7 +117,7 @@ var kill = function(app, agent, msg, cb) { var sid, record; var serverIds = []; var count = utils.size(agent.idMap); - var latch = countDownLatch.createCountDownLatch(count, {timeout: Constants.TIME.TIME_WAIT_MASTER_KILL}, function(isTimeout) { + var latch = countDownLatch.createCountDownLatch(count, {timeout: Constants.TIME.TIME_WAIT_ALL_MONITORS_KILL}, function(isTimeout) { if (!isTimeout) { utils.invokeCallback(cb, null, {code: 'ok'}); } else { @@ -125,7 +125,7 @@ var kill = function(app, agent, msg, cb) { } setTimeout(function() { process.exit(-1); - }, Constants.TIME.TIME_WAIT_MONITOR_KILL); + }, Constants.TIME.TIME_WAIT_MASTER_KILL); }); var agentRequestCallback = function(msg) { diff --git a/lib/util/constants.js b/lib/util/constants.js index 99987e45b..48ed83470 100644 --- a/lib/util/constants.js +++ b/lib/util/constants.js @@ -101,8 +101,9 @@ module.exports = { TIME_WAIT_KILL: 5 * 1000, TIME_WAIT_RESTART: 5 * 1000, TIME_WAIT_COUNTDOWN: 10 * 1000, - TIME_WAIT_MASTER_KILL: 2 * 60 * 1000, + TIME_WAIT_MASTER_KILL: 2 * 1000, TIME_WAIT_MONITOR_KILL: 2 * 1000, + TIME_WAIT_ALL_MONITORS_KILL: 2 * 60 * 1000, TIME_WAIT_PING: 30 * 1000, TIME_WAIT_MAX_PING: 5 * 60 * 1000, DEFAULT_UDP_HEARTBEAT_TIME: 20 * 1000,