summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Jian Ping <wujp@greatld.com>2021-06-11 12:32:20 +0800
committerJens Geyer <Jens-G@users.noreply.github.com>2022-10-25 22:36:49 +0200
commit8940715a1b8c2808cd2654687552dbbda3509efa (patch)
treea1516c63bbd0886c318c0ffb960a7601bfb8e993
parent6aba57bb6b0201f2138a503cbf22123901f32f72 (diff)
downloadthrift-8940715a1b8c2808cd2654687552dbbda3509efa.tar.gz
fix reconnect issue for nodejs
-rw-r--r--lib/nodejs/lib/thrift/connection.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js
index 25e34ed42..5faa24c9f 100644
--- a/lib/nodejs/lib/thrift/connection.js
+++ b/lib/nodejs/lib/thrift/connection.js
@@ -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;
@@ -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();
};
@@ -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) {
+ self.emit("close");
+ if (this.retry_timer) {
+ clearTimeout(this.retry_timer);
+ this.retry_timer = null;
+ }
+ return;
+ }
+
// If a retry is already in progress, just let that happen
if (this.retry_timer) {
return;
@@ -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;
@@ -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
});