fix reconnect issue for nodejs
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js
index 25e34ed..5faa24c 100644
--- a/lib/nodejs/lib/thrift/connection.js
+++ b/lib/nodejs/lib/thrift/connection.js
@@ -44,6 +44,7 @@
   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 @@
 util.inherits(Connection, EventEmitter);
 
 Connection.prototype.end = function() {
+  this.forceClose = true;
   this.connection.end();
 };
 
@@ -198,6 +200,16 @@
   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 @@
   });
 
   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 @@
 
 exports.createConnection = function(host, port, options) {
   var stream = net.createConnection( {
-    port: port, 
+    port: port,
     host: host,
     timeout: options.connect_timeout || options.timeout || 0
   });