Comparing version 0.7.18 to 0.7.20
@@ -26,3 +26,3 @@ /*! | ||
var VERSION = '0.7.18', | ||
var VERSION = '0.7.20', | ||
@@ -95,2 +95,4 @@ DEFAULT_PORT = 4222, | ||
REQ_TIMEOUT_MSG_PREFIX = 'The request timed out for subscription id: ', | ||
STALE_CONNECTION_ERR = "stale connection", | ||
PERMISSIONS_ERR = "permissions violation", | ||
@@ -420,3 +422,3 @@ // Pedantic Mode support | ||
stream.on('close', function(hadError) { | ||
client.closeStream(); | ||
client.closeStream(); | ||
client.emit('disconnect'); | ||
@@ -433,3 +435,3 @@ if (client.closed === true || | ||
stream.on('error', function(exception) { | ||
// If we were connected just return, close event will process | ||
// If we were connected just return, close event will process | ||
if (client.wasConnected === true && client.currentServer.didConnect === true) { | ||
@@ -559,4 +561,10 @@ return; | ||
this.selectServer(); | ||
// Create the stream. | ||
this.stream = net.createConnection(this.url.port, this.url.hostname); | ||
// See #45 if we have a stream release the listeners | ||
// otherwise in addition to the leak events will fire fire | ||
if(this.stream) { | ||
this.stream.removeAllListeners(); | ||
this.stream.end(); | ||
} | ||
// Create the stream | ||
this.stream = net.createConnection(this.url.port, this.url.hostname); | ||
// Setup the proper handlers. | ||
@@ -611,3 +619,3 @@ this.setupHandlers(); | ||
this.stream.destroy(); | ||
this.stream = null; | ||
this.stream = null; | ||
} | ||
@@ -765,2 +773,7 @@ if (this.connected === true || this.closed === true) { | ||
if(! client.stream) { | ||
// if we are here, the stream was reaped and errors raised | ||
// if we continue. | ||
return; | ||
} | ||
// unpause if needed. | ||
@@ -795,3 +808,4 @@ // FIXME(dlc) client.stream.isPaused() causes 0.10 to fail | ||
} else if ((m = ERR.exec(buf)) !== null) { | ||
client.emit('error', new NatsError(m[1], NATS_PROTOCOL_ERR)); | ||
client.processErr(m[1]); | ||
return; | ||
} else if ((m = PONG.exec(buf)) !== null) { | ||
@@ -846,2 +860,7 @@ var cb = client.pongs && client.pongs.shift(); | ||
} | ||
// if we have a stream, this is from an old connection, reap it | ||
if(client.stream) { | ||
client.stream.removeAllListeners(); | ||
client.stream.end(); | ||
} | ||
client.stream = tls.connect(tlsOpts, function() { | ||
@@ -999,2 +1018,21 @@ client.flushPending(); | ||
/** | ||
* ProcessErr processes any error messages from the server | ||
* | ||
* @api private | ||
*/ | ||
Client.prototype.processErr = function(s) { | ||
// current NATS clients, will raise an error and close on any errors | ||
// except stale connection and permission errors | ||
var m = s ? s.toLowerCase() : ''; | ||
if(m.indexOf(STALE_CONNECTION_ERR) !== -1) { | ||
this.scheduleReconnect(); | ||
} else if(m.indexOf(PERMISSIONS_ERR) !== -1) { | ||
this.emit('permission_error', new NatsError(s, NATS_PROTOCOL_ERR)); | ||
} else { | ||
this.emit('error', new NatsError(s, NATS_PROTOCOL_ERR)); | ||
this.closeStream(); | ||
} | ||
}; | ||
/** | ||
* Push a new cluster server. | ||
@@ -1001,0 +1039,0 @@ * |
{ | ||
"name": "nats", | ||
"version": "0.7.18", | ||
"version": "0.7.20", | ||
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
50049
1330