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.
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js
index 0ea50d3..23cb01c 100644
--- a/lib/nodejs/lib/thrift/connection.js
+++ b/lib/nodejs/lib/thrift/connection.js
@@ -82,14 +82,12 @@
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.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 {