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 +};