Skip to content
Merged
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
19 changes: 13 additions & 6 deletions lib/nodejs/lib/thrift/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var Connection = exports.Connection = function(stream, options) {
this.protocol = this.options.protocol || TBinaryProtocol;
this.offline_queue = [];
this.connected = false;
this.forceClose = false;
this.initialize_retry_vars();

this._debug = this.options.debug || false;
Expand Down Expand Up @@ -159,6 +160,7 @@ var Connection = exports.Connection = function(stream, options) {
util.inherits(Connection, EventEmitter);

Connection.prototype.end = function() {
this.forceClose = true;
this.connection.end();
};

Expand Down Expand Up @@ -198,6 +200,16 @@ Connection.prototype.connection_gone = function () {
var self = this;
this.connected = false;

// If closed by manual, emit close event and cancel reconnect process
if(this.forceClose) {
if (this.retry_timer) {
clearTimeout(this.retry_timer);
this.retry_timer = null;
}
self.emit("close");
return;
}

// If a retry is already in progress, just let that happen
if (this.retry_timer) {
return;
Expand Down Expand Up @@ -230,11 +242,6 @@ Connection.prototype.connection_gone = function () {
});

this.retry_timer = setTimeout(function () {
if (self.connection.destroyed) {
self.retry_timer = null;
return;
}

log.debug("Retrying connection...");

self.retry_totaltime += self.retry_delay;
Expand All @@ -257,7 +264,7 @@ Connection.prototype.connection_gone = function () {

exports.createConnection = function(host, port, options) {
var stream = net.createConnection( {
port: port,
port: port,
host: host,
timeout: options.connect_timeout || options.timeout || 0
});
Expand Down