Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix: catch thrown maConn errors in listener
Browse files Browse the repository at this point in the history
When upgrading sockets to MultiaddConnections, it's possible for an error to be thrown.
This can crash the application if a client disconnects prior to the listener
uprading the socket, as is likely occurring in #121. Errors will now be caught and logged
when attempting to upgrade the socket.
  • Loading branch information
jacobheun committed Feb 13, 2020
1 parent 0c2d84e commit 4ff94cd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ module.exports = ({ handler, upgrader }, options) => {
// Avoid uncaught errors caused by unstable connections
socket.on('error', err => log('socket error', err))

const maConn = toConnection(socket, { listeningAddr })
log('new inbound connection %s', maConn.remoteAddr)

let maConn
let conn
try {
maConn = toConnection(socket, { listeningAddr })
log('new inbound connection %s', maConn.remoteAddr)
conn = await upgrader.upgradeInbound(maConn)
} catch (err) {
log.error('inbound connection failed to upgrade', err)
return maConn.close()
log.error('inbound connection failed', err)
return maConn && maConn.close()
}

log('inbound connection %s upgraded', maConn.remoteAddr)
Expand Down

0 comments on commit 4ff94cd

Please sign in to comment.