From 1e1432f76dab1ecd75cf56b2fa726024d9b447ef Mon Sep 17 00:00:00 2001 From: prasad83 Date: Wed, 19 Nov 2014 12:34:30 +0530 Subject: [PATCH] Binary transport - destroy socket during close Using socket.end is hanging the process - socket.destroy with case-handling seem to be making it work. Refer: http://nodejs.org/api/net.html#net_socket_destroy vs http://nodejs.org/api/net.html#net_socket_end_data_encoding --- lib/transport/binary/connection.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/transport/binary/connection.js b/lib/transport/binary/connection.js index 04960a4..9f54898 100644 --- a/lib/transport/binary/connection.js +++ b/lib/transport/binary/connection.js @@ -133,7 +133,10 @@ Connection.prototype.createSocket = function () { */ Connection.prototype.close = function () { if (this.socket) { - this.socket.end(); + //this.socket.end(); + // to avoid hangup of process we need to destroy socket completely. + this.socket.removeAllListeners(); + this.socket.destroy(); this.socket = null; } return this; @@ -219,7 +222,7 @@ Connection.prototype.negotiateProtocol = function () { }.bind(this)); this.socket.once('close', function (err) { this.logger.debug('connection closed during protocol negotiation: ' + err); - this.socket.removeAllListeners(); + if (this.socket) this.socket.removeAllListeners(); // close earlier could have destroyed set socket to null. this.connecting = false; if (err) { reject(new errors.Connection(err.code, err.message)); @@ -367,4 +370,4 @@ Connection.prototype.process = function (buffer, offset) { } } return offset; -}; \ No newline at end of file +};