Skip to content

Commit

Permalink
Fixed; only clear handlers if they were set. [level09]
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Jun 30, 2011
1 parent 9b40977 commit 40c1f8d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Transport.prototype.setHandlers = function () {
this.socket.on('close', this.bound.close);
this.socket.on('error', this.bound.error);
this.socket.on('drain', this.bound.drain);

this.handlersSet = true;
};

/**
Expand All @@ -124,14 +126,16 @@ Transport.prototype.setHandlers = function () {
*/

Transport.prototype.clearHandlers = function () {
this.store.unsubscribe('disconnect-force:' + this.id);
this.store.unsubscribe('heartbeat-clear:' + this.id);
this.store.unsubscribe('dispatch:' + this.id);

this.socket.removeListener('end', this.bound.end);
this.socket.removeListener('close', this.bound.close);
this.socket.removeListener('error', this.bound.error);
this.socket.removeListener('drain', this.bound.drain);
if (this.handlersSet) {
this.store.unsubscribe('disconnect-force:' + this.id);
this.store.unsubscribe('heartbeat-clear:' + this.id);
this.store.unsubscribe('dispatch:' + this.id);

this.socket.removeListener('end', this.bound.end);
this.socket.removeListener('close', this.bound.close);
this.socket.removeListener('error', this.bound.error);
this.socket.removeListener('drain', this.bound.drain);
}
};

/**
Expand Down

0 comments on commit 40c1f8d

Please sign in to comment.