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

Commit ff03137

Browse files
vasco-santosjacobheun
authored andcommitted
fix: transport should not handle connection if upgradeInbound throws (#16)
* fix: transport should not handle connection if upgradeInbound throws * chore: address review
1 parent 2803e64 commit ff03137

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"libp2p-tcp": "^0.14.1",
4747
"multiaddr": "^7.1.0",
4848
"p-limit": "^2.2.1",
49+
"p-wait-for": "^3.1.0",
4950
"peer-id": "^0.13.3",
5051
"sinon": "^7.5.0",
5152
"streaming-iterables": "^4.1.0"

src/transport/tests/listen-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const expect = chai.expect
88
chai.use(dirtyChai)
99
const sinon = require('sinon')
1010

11+
const pWaitFor = require('p-wait-for')
1112
const pipe = require('it-pipe')
1213
const { isValidTick } = require('./utils')
1314

@@ -92,6 +93,23 @@ module.exports = (common) => {
9293
expect(upgradeSpy.callCount).to.equal(2)
9394
})
9495

96+
it('should not handle connection if upgradeInbound throws', async () => {
97+
sinon.stub(upgrader, 'upgradeInbound').throws()
98+
99+
const listener = transport.createListener(() => {
100+
throw new Error('should not handle the connection if upgradeInbound throws')
101+
})
102+
103+
// Listen
104+
await listener.listen(addrs[0])
105+
106+
// Create a connection to the listener
107+
const socket = await transport.dial(addrs[0])
108+
109+
await pWaitFor(() => typeof socket.timeline.close === 'number')
110+
await listener.close()
111+
})
112+
95113
describe('events', () => {
96114
it('connection', (done) => {
97115
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')

0 commit comments

Comments
 (0)