summaryrefslogtreecommitdiff
path: root/lib/nodejs/lib/thrift
diff options
context:
space:
mode:
authorRandy Abernethy <ra@apache.org>2016-05-12 22:02:58 -0700
committerRandy Abernethy <ra@apache.org>2016-05-12 22:02:58 -0700
commitd7f87aa5f2ceca288b9159b2d3e70497c330aa38 (patch)
treeed525477616992bfc0cc0a84abacdf2579c7a7ab /lib/nodejs/lib/thrift
parent9b954e6a469fef18682314458e6fc4af2dd84add (diff)
downloadthrift-d7f87aa5f2ceca288b9159b2d3e70497c330aa38.tar.gz
THRIFT-3787: connection close code fix for ssl
CLIENT: Node PATCH: JAMES REGGIO james.reggio@gmail.com This closes #986 commit 449b1d711f91a9252b64351a71e44945e4432911 Author: James Reggio <james.reggio@gmail.com> Date: 2016-04-13T23:33:40Z THRIFT-3787 Fix Node.js Connection object error handling The `connected` property on a Connection instances was not accurately maintained if reconnection retries are not enabled. Furthermore, reconnection retries are not possible with secure sockets, so this commit returns early in that case, preventing long delays.
Diffstat (limited to 'lib/nodejs/lib/thrift')
-rw-r--r--lib/nodejs/lib/thrift/connection.js13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js
index 0ea50d340..23cb01c79 100644
--- a/lib/nodejs/lib/thrift/connection.js
+++ b/lib/nodejs/lib/thrift/connection.js
@@ -82,14 +82,12 @@ var Connection = exports.Connection = function(stream, options) {
this.connection.addListener("error", function(err) {
// Only emit the error if no-one else is listening on the connection
- // or if someone is listening on us
+ // or if someone is listening on us, because Node turns unhandled
+ // 'error' events into exceptions.
if (self.connection.listeners('error').length === 1 ||
self.listeners('error').length > 0) {
self.emit("error", err);
}
- // "error" events get turned into exceptions if they aren't listened for. If the user handled this error
- // then we should try to reconnect.
- self.connection_gone();
});
// Add a close listener
@@ -185,19 +183,18 @@ Connection.prototype.write = function(data) {
Connection.prototype.connection_gone = function () {
var self = this;
+ this.connected = false;
// If a retry is already in progress, just let that happen
if (this.retry_timer) {
return;
}
- if (!this.max_attempts) {
+ // We cannot reconnect a secure socket.
+ if (!this.max_attempts || this.ssl) {
self.emit("close");
return;
}
- this.connected = false;
- this.ready = false;
-
if (this.retry_max_delay !== null && this.retry_delay >= this.retry_max_delay) {
this.retry_delay = this.retry_max_delay;
} else {