Skip to content

Commit 79e82d5

Browse files
committed
fix: upgrader should abort stream on close based on inbound limits (#1578)
1 parent b5a1219 commit 79e82d5

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/upgrader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ function findIncomingStreamLimit (protocol: string, registrar: Registrar): numbe
7373
function findOutgoingStreamLimit (protocol: string, registrar: Registrar): number | undefined {
7474
try {
7575
const { options } = registrar.getHandler(protocol)
76-
7776
return options.maxOutboundStreams
7877
} catch (err: any) {
7978
if (err.code !== codes.ERR_NO_HANDLER_FOR_PROTOCOL) {
@@ -392,9 +391,10 @@ export class DefaultUpgrader implements Upgrader {
392391
const streamCount = countStreams(protocol, 'inbound', connection)
393392

394393
if (streamCount === incomingLimit) {
395-
muxedStream.abort(new CodeError(`Too many inbound protocol streams for protocol "${protocol}" - limit ${incomingLimit}`, codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS))
394+
const err = new CodeError(`Too many inbound protocol streams for protocol "${protocol}" - limit ${incomingLimit}`, codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS)
395+
muxedStream.abort(err)
396396

397-
return
397+
throw err
398398
}
399399

400400
// after the handshake the returned stream can have early data so override

test/upgrading/upgrader.spec.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { DefaultComponents } from '../../src/components.js'
3434
import { StubbedInstance, stubInterface } from 'sinon-ts'
3535
import { yamux } from '@chainsafe/libp2p-yamux'
3636
import { EventEmitter } from '@libp2p/interfaces/events'
37+
import { logger } from '@libp2p/logger'
3738

3839
const addrs = [
3940
multiaddr('/ip4/127.0.0.1/tcp/0'),
@@ -664,7 +665,10 @@ describe('libp2p.upgrader', () => {
664665
webSockets()
665666
],
666667
streamMuxers: [
667-
yamux()
668+
yamux({
669+
log: logger('yamux:local')
670+
})
671+
// mplex()
668672
],
669673
connectionEncryption: [
670674
plaintext()
@@ -678,7 +682,10 @@ describe('libp2p.upgrader', () => {
678682
webSockets()
679683
],
680684
streamMuxers: [
681-
yamux()
685+
yamux({
686+
log: logger('yamux:remote')
687+
})
688+
// mplex()
682689
],
683690
connectionEncryption: [
684691
plaintext()
@@ -726,8 +733,7 @@ describe('libp2p.upgrader', () => {
726733
webSockets()
727734
],
728735
streamMuxers: [
729-
yamux(),
730-
mplex()
736+
yamux()
731737
],
732738
connectionEncryption: [
733739
plaintext()
@@ -741,8 +747,7 @@ describe('libp2p.upgrader', () => {
741747
webSockets()
742748
],
743749
streamMuxers: [
744-
yamux(),
745-
mplex()
750+
yamux()
746751
],
747752
connectionEncryption: [
748753
plaintext()

0 commit comments

Comments
 (0)