Skip to content

Commit

Permalink
fix: silence max listeners exceeded warning (#62)
Browse files Browse the repository at this point in the history
If we have more than 10x streams open accross all yamux muxer
instances node will log warnings about too many listeners being
added to the shutdown controller signal.

This is fine, increase the max number of listeners.
  • Loading branch information
achingbrain authored Nov 12, 2023
1 parent 59e73d8 commit cce9446
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/muxer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CodeError } from '@libp2p/interface/errors'
import { setMaxListeners } from '@libp2p/interface/events'
import { logger, type Logger } from '@libp2p/logger'
import { abortableSource } from 'abortable-iterator'
import { pipe } from 'it-pipe'
Expand Down Expand Up @@ -85,6 +86,7 @@ export class YamuxMuxer implements StreamMuxer {
verifyConfig(this.config)

this.closeController = new AbortController()
setMaxListeners(Infinity, this.closeController.signal)

this.onIncomingStream = init.onIncomingStream
this.onStreamEnd = init.onStreamEnd
Expand Down Expand Up @@ -272,7 +274,15 @@ export class YamuxMuxer implements StreamMuxer {

this.log?.trace('muxer close reason=%s', reason)

options.signal = options.signal ?? AbortSignal.timeout(CLOSE_TIMEOUT)
if (options.signal == null) {
const signal = AbortSignal.timeout(CLOSE_TIMEOUT)
setMaxListeners(Infinity, signal)

options = {
...options,
signal
}
}

try {
await Promise.all(
Expand Down

0 comments on commit cce9446

Please sign in to comment.