Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

修改一些存在歧义的代码 #1188

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/connectors/commands/heartbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -55,19 +55,19 @@ Command.prototype.handle = function(socket) {
}
};

Command.prototype.clear = function(id) {
Command.prototype.clearTimers = function(id) {
var tid = this.timeouts[id];
if(tid) {
clearTimeout(tid);
delete this.timeouts[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];
}
};
16 changes: 7 additions & 9 deletions lib/connectors/udpsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ 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 {
utils.invokeCallback(cb, null, {code: 'remained', serverIds: serverIds});
}
setTimeout(function() {
process.exit(-1);
}, Constants.TIME.TIME_WAIT_MONITOR_KILL);
}, Constants.TIME.TIME_WAIT_MASTER_KILL);
});

var agentRequestCallback = function(msg) {
Expand Down
3 changes: 2 additions & 1 deletion lib/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down