fix: catch thrown maConn errors in listener

This commit is contained in:
Vasco Santos 2020-02-26 15:14:54 +01:00 committed by Jacob Heun
parent d630b3288d
commit 8bfb19a78f

View File

@ -14,16 +14,15 @@ module.exports = ({ handler, upgrader }, options = {}) => {
const listener = new EventEmitter() const listener = new EventEmitter()
const server = createServer(options, async (stream) => { const server = createServer(options, async (stream) => {
const maConn = toConnection(stream) let maConn, conn
log('new inbound connection %s', maConn.remoteAddr)
let conn
try { try {
maConn = toConnection(stream)
log('new inbound connection %s', maConn.remoteAddr)
conn = await upgrader.upgradeInbound(maConn) conn = await upgrader.upgradeInbound(maConn)
} catch (err) { } catch (err) {
log.error('inbound connection failed to upgrade', err) log.error('inbound connection failed to upgrade', err)
return maConn.close() return maConn && maConn.close()
} }
log('inbound connection %s upgraded', maConn.remoteAddr) log('inbound connection %s upgraded', maConn.remoteAddr)