cluster-client
Advanced tools
Comparing version 1.3.1 to 1.3.2
1.3.2 / 2017-03-08 | ||
================== | ||
* fix: fix leader subscribe issue & heartbeat timeout issue (#15) | ||
1.3.1 / 2017-03-07 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -5,3 +5,5 @@ 'use strict'; | ||
const co = require('co'); | ||
const is = require('is-type-of'); | ||
const Base = require('sdk-base'); | ||
const assert = require('assert'); | ||
const utils = require('./utils'); | ||
@@ -123,2 +125,4 @@ const Leader = require('./leader'); | ||
[subscribe](reg, listener) { | ||
assert(is.function(listener), `[ClusterClient#${this._options.name}] subscribe(reg, listener) listener should be a function`); | ||
this[logger].info('[ClusterClient#%s] subscribe %j', this._options.name, reg); | ||
@@ -125,0 +129,0 @@ const key = this._options.formatKey(reg); |
@@ -124,3 +124,5 @@ 'use strict'; | ||
this.logger.info('[Follower#%s] subscribe %j', this.options.name, reg); | ||
listener(this._subData.get(key)); | ||
process.nextTick(() => { | ||
listener(this._subData.get(key)); | ||
}); | ||
} | ||
@@ -127,0 +129,0 @@ return this; |
@@ -54,2 +54,6 @@ 'use strict'; | ||
// maxIdleTime is 3 times of heartbeatInterval | ||
const heartbeatInterval = this.options.heartbeatInterval; | ||
const maxIdleTime = this.options.heartbeatInterval * 3; | ||
this._heartbeatTimer = setInterval(() => { | ||
@@ -59,4 +63,4 @@ const now = Date.now(); | ||
const dur = now - conn.lastActiveTime; | ||
if (dur > this._options.heartbeatInterval) { | ||
const err = new Error(`client no response in ${dur}ms, maybe the connection is close on other side.`); | ||
if (dur > maxIdleTime) { | ||
const err = new Error(`client no response in ${dur}ms exceeding maxIdleTime ${maxIdleTime}ms, maybe the connection is close on other side.`); | ||
err.name = 'ClusterClientNoResponseError'; | ||
@@ -66,3 +70,3 @@ conn.close(err); | ||
} | ||
}, this._options.heartbeatInterval); | ||
}, heartbeatInterval); | ||
} | ||
@@ -82,3 +86,3 @@ | ||
isMock: { value: true }, | ||
key: { value: `mock_conn_${Date.now()}` }, | ||
key: { value: `${this.options.name}_mock_conn_${utils.nextId()}` }, | ||
lastActiveTime: { | ||
@@ -92,3 +96,3 @@ get() { | ||
const result = transcode.decode(req.data); | ||
listener && listener(result); | ||
listener(result); | ||
}, | ||
@@ -95,0 +99,0 @@ }, |
{ | ||
"name": "cluster-client", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Sharing Connection among Multi-Process Nodejs", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
57457
1491
1