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

Commit 21f8747

Browse files
vasco-santosjacobheun
authored andcommitted
fix: transport should not handle connection if upgradeInbound throws (#119)
1 parent 657d3e6 commit 21f8747

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"aegir": "^20.4.1",
3737
"chai": "^4.2.0",
3838
"dirty-chai": "^2.0.1",
39-
"libp2p-interfaces": "^0.1.6",
39+
"libp2p-interfaces": "^0.2.0",
4040
"it-pipe": "^1.1.0",
4141
"sinon": "^7.5.0",
4242
"streaming-iterables": "^4.1.1"

src/listener.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
const net = require('net')
44
const EventEmitter = require('events')
5-
const log = require('debug')('libp2p:tcp:listener')
5+
const debug = require('debug')
6+
const log = debug('libp2p:tcp:listener')
7+
log.error = debug('libp2p:tcp:listener:error')
8+
69
const toConnection = require('./socket-to-conn')
710
const { CODE_P2P } = require('./constants')
811
const {
@@ -20,7 +23,14 @@ module.exports = ({ handler, upgrader }, options) => {
2023
const maConn = toConnection(socket, { listeningAddr })
2124
log('new inbound connection %s', maConn.remoteAddr)
2225

23-
const conn = await upgrader.upgradeInbound(maConn)
26+
let conn
27+
try {
28+
conn = await upgrader.upgradeInbound(maConn)
29+
} catch (err) {
30+
log.error('inbound connection failed to upgrade', err)
31+
return maConn.close()
32+
}
33+
2434
log('inbound connection %s upgraded', maConn.remoteAddr)
2535

2636
trackConn(server, maConn)

0 commit comments

Comments
 (0)