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

Commit

Permalink
fix: catch inbound upgrade errors (#96)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
jacobheun committed Oct 30, 2019
1 parent b5496fb commit 5b59fc3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const EventEmitter = require('events')
const os = require('os')
const multiaddr = require('multiaddr')
const { createServer } = require('it-ws')

const log = require('debug')('libp2p:websockets:listener')
const debug = require('debug')
const log = debug('libp2p:websockets:listener')
log.error = debug('libp2p:websockets:listener:error')

const toConnection = require('./socket-to-conn')

Expand All @@ -17,7 +18,14 @@ module.exports = ({ handler, upgrader }, options = {}) => {

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

const conn = await upgrader.upgradeInbound(maConn)
let conn
try {
conn = await upgrader.upgradeInbound(maConn)
} catch (err) {
log.error('inbound connection failed to upgrade', err)
return maConn.close()
}

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

trackConn(server, maConn)
Expand Down

0 comments on commit 5b59fc3

Please sign in to comment.