Skip to content

Commit

Permalink
Make sure not to trigger multiple timeouts when closing
Browse files Browse the repository at this point in the history
Important fix for polling transports.
  • Loading branch information
rauchg committed Jan 10, 2011
1 parent f5b2028 commit 71e7756
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/socket.io/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Client.prototype._onConnect = function(req, res){
this.request = req;
this.response = res;
this.connection = req.connection;

this.connection.addListener('end', function(){
self._onClose();
});
Expand Down Expand Up @@ -125,14 +125,11 @@ Client.prototype._onHeartbeat = function(h){
};

Client.prototype._onClose = function(skipDisconnect){
if (!this._open) return this;
var self = this;
if (this._heartbeatInterval) clearTimeout(this._heartbeatInterval);
if (this._heartbeatTimeout) clearTimeout(this._heartbeatTimeout);
this._open = false;
if (this.connection){
this.connection.end();
this.connection = null;
}
this.request = null;
this.response = null;
if (skipDisconnect !== false){
Expand All @@ -148,6 +145,10 @@ Client.prototype._onClose = function(skipDisconnect){
Client.prototype._onDisconnect = function(){
if (this._open) this._onClose(true);
if (this._disconnectTimeout) clearTimeout(this._disconnectTimeout);
if (this.connection){
this.connection.end();
this.connection = null;
}
this._writeQueue = [];
this.connected = false;
if (this.handshaked){
Expand Down

0 comments on commit 71e7756

Please sign in to comment.