diff --git a/lib/client/client.js b/lib/client/client.js index 4643e57..15820ea 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -838,8 +838,8 @@ Client.prototype._connect = function _connect() { socket.destroy(); cb(err || new Error('client error during setup')); } - // Work around lack of close event on tls.socket - ((self.secure) ? socket.socket : socket).once('close', bail); + // Work around lack of close event on tls.socket in node < 0.11 + ((socket.socket) ? socket.socket : socket).once('close', bail); socket.once('error', bail); socket.once('end', bail); socket.once('timeout', bail); @@ -882,8 +882,8 @@ Client.prototype._connect = function _connect() { .removeAllListeners('end') .removeAllListeners('timeout'); - // Work around lack of close event on tls.socket - ((self.secure) ? socket.socket : socket).once('close', + // Work around lack of close event on tls.socket in node < 0.11 + ((socket.socket) ? socket.socket : socket).once('close', self._onClose.bind(self)); socket.on('end', function onEnd() { if (log.trace()) @@ -970,11 +970,7 @@ Client.prototype._onClose = function _onClose(had_err) { this.socket = null; this.connected = false; - if (!this.secure) { - socket.removeAllListeners('close'); - } else { - socket.socket.removeAllListeners('close'); - } + ((socket.socket) ? socket.socket : socket).removeAllListeners('close'); if (this.log.trace()) this.log.trace('close event had_err=%s', had_err ? 'yes' : 'no');