diff --git a/lib/socket.js b/lib/socket.js index 71a95ee8c..eee51d216 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -92,6 +92,7 @@ Socket.prototype.onPacket = function (packet) { break; case 'error': + this.transport.close(); this.onClose('parse error'); break; @@ -220,6 +221,10 @@ Socket.prototype.clearTransport = function () { this.transport.on('error', function(){ debug('error triggered by discarded transport'); }); + + // ensure transport won't stay open + this.transport.close(); + clearTimeout(this.pingTimeoutTimer); }; diff --git a/lib/transport.js b/lib/transport.js index 993896bf0..d1648227a 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -57,6 +57,8 @@ Transport.prototype.onRequest = function (req) { */ Transport.prototype.close = function (fn) { + if ('closed' == this.readyState || 'closing' == this.readyState) return; + this.readyState = 'closing'; this.doClose(fn || noop); };