Skip to content

Commit 40c1f8d

Browse files
committed
Fixed; only clear handlers if they were set. [level09]
1 parent 9b40977 commit 40c1f8d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/transport.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Transport.prototype.setHandlers = function () {
115115
this.socket.on('close', this.bound.close);
116116
this.socket.on('error', this.bound.error);
117117
this.socket.on('drain', this.bound.drain);
118+
119+
this.handlersSet = true;
118120
};
119121

120122
/**
@@ -124,14 +126,16 @@ Transport.prototype.setHandlers = function () {
124126
*/
125127

126128
Transport.prototype.clearHandlers = function () {
127-
this.store.unsubscribe('disconnect-force:' + this.id);
128-
this.store.unsubscribe('heartbeat-clear:' + this.id);
129-
this.store.unsubscribe('dispatch:' + this.id);
130-
131-
this.socket.removeListener('end', this.bound.end);
132-
this.socket.removeListener('close', this.bound.close);
133-
this.socket.removeListener('error', this.bound.error);
134-
this.socket.removeListener('drain', this.bound.drain);
129+
if (this.handlersSet) {
130+
this.store.unsubscribe('disconnect-force:' + this.id);
131+
this.store.unsubscribe('heartbeat-clear:' + this.id);
132+
this.store.unsubscribe('dispatch:' + this.id);
133+
134+
this.socket.removeListener('end', this.bound.end);
135+
this.socket.removeListener('close', this.bound.close);
136+
this.socket.removeListener('error', this.bound.error);
137+
this.socket.removeListener('drain', this.bound.drain);
138+
}
135139
};
136140

137141
/**

0 commit comments

Comments
 (0)