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

fix: transport should not handle connection if upgradeInbound throws #16

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/transport/tests/listen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ module.exports = (common) => {
expect(upgradeSpy.callCount).to.equal(2)
})

it('should not handle connection if upgradeInbound throws', async () => {
sinon.stub(upgrader, 'upgradeInbound').throws()

const listener = transport.createListener(() => {
throw new Error('should not handle the connection if upgradeInbound throws')
})

// Listen
await listener.listen(addrs[0])

// Create a connection to the listener
const socket = await transport.dial(addrs[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vasco-santos I think we should validate the socket was closed as well. Since the listener throws, it should hangup, so the dial socket should get closed. We could wait for timeline.close to exist after the dial before closing everything. await pWaitFor(() => typeof socket.timeline.close === 'number') or something similar.

Other than that, this looks good. I mainly just want to ensure we are properly closing the sockets on inbound errors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that is better


await socket.close()
await listener.close()
})

describe('events', () => {
it('connection', (done) => {
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
Expand Down