Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix "Error: listener must be a function"
The websocket can error and close before the "connection" event has
fired. In that situation, socket.onMessageBound, etc. will be undefined.

Closes #148
  • Loading branch information
feross committed Apr 22, 2016
commit fafbb25367ee3945ba30696cb45637183d0bc4ec
12 changes: 9 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,19 @@ Server.prototype._onWebSocketClose = function (socket) {
socket.peerId = null
socket.infoHashes = null

socket.removeListener('message', socket.onMessageBound)
if (typeof socket.onMessageBound === 'function') {
socket.removeListener('message', socket.onMessageBound)
}
socket.onMessageBound = null

socket.removeListener('error', socket.onErrorBound)
if (typeof socket.onErrorBound === 'function') {
socket.removeListener('error', socket.onErrorBound)
}
socket.onErrorBound = null

socket.removeListener('close', socket.onCloseBound)
if (typeof socket.onCloseBound === 'function') {
socket.removeListener('close', socket.onCloseBound)
}
socket.onCloseBound = null
}

Expand Down