You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2022/10/25 20:37:04 UTC
[thrift] 01/02: fix reconnect issue for nodejs
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
commit 8940715a1b8c2808cd2654687552dbbda3509efa
Author: Wu Jian Ping <wu...@greatld.com>
AuthorDate: Fri Jun 11 12:32:20 2021 +0800
fix reconnect issue for nodejs
---
lib/nodejs/lib/thrift/connection.js | 19 +++++++++++++------
1 file 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
});