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

Commit

Permalink
fix: transport should not handle connection if upgradeInbound throws
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 20, 2019
1 parent 657d3e6 commit 1ecc92f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"aegir": "^20.4.1",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"libp2p-interfaces": "^0.1.6",
"libp2p-interfaces": "libp2p/js-interfaces#fix/transport-should-not-handle-connection-if-upgradeInbound-throws",
"it-pipe": "^1.1.0",
"sinon": "^7.5.0",
"streaming-iterables": "^4.1.1"
Expand Down
14 changes: 12 additions & 2 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

const net = require('net')
const EventEmitter = require('events')
const log = require('debug')('libp2p:tcp:listener')
const debug = require('debug')
const log = debug('libp2p:tcp:listener')
log.error = debug('libp2p:tcp:listener:error')

const toConnection = require('./socket-to-conn')
const { CODE_P2P } = require('./constants')
const {
Expand All @@ -20,7 +23,14 @@ module.exports = ({ handler, upgrader }, options) => {
const maConn = toConnection(socket, { listeningAddr })
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 1ecc92f

Please sign in to comment.