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

Commit 86db568

Browse files
authored
fix: catch thrown maConn errors in listener (#122)
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.
1 parent 0c2d84e commit 86db568

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/listener.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ module.exports = ({ handler, upgrader }, options) => {
2020
// Avoid uncaught errors caused by unstable connections
2121
socket.on('error', err => log('socket error', err))
2222

23-
const maConn = toConnection(socket, { listeningAddr })
24-
log('new inbound connection %s', maConn.remoteAddr)
25-
23+
let maConn
2624
let conn
2725
try {
26+
maConn = toConnection(socket, { listeningAddr })
27+
log('new inbound connection %s', maConn.remoteAddr)
2828
conn = await upgrader.upgradeInbound(maConn)
2929
} catch (err) {
30-
log.error('inbound connection failed to upgrade', err)
31-
return maConn.close()
30+
log.error('inbound connection failed', err)
31+
return maConn && maConn.close()
3232
}
3333

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

0 commit comments

Comments
 (0)