Skip to content

Commit

Permalink
fix: increase maxlisteners on event target
Browse files Browse the repository at this point in the history
Sometimes you encounter peers with lots of addresses. When this happens
you can attach more than 10x event listeners to the abort signal we
use to abort all the dials - this causes node to print a warning
which is misleading.

This PR increases the default number of listeners on the signal.

Fixes #900
  • Loading branch information
achingbrain committed Dec 6, 2021
1 parent ae21299 commit 34d4a51
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dialer/dial-request.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict'

const errCode = require('err-code')
const AbortController = require('abort-controller').default
const { anySignal } = require('any-signal')
// @ts-ignore p-fifo does not export types
const FIFO = require('p-fifo')
const pAny = require('p-any')
// @ts-expect-error setMaxListeners is missing from the types
const { setMaxListeners } = require('events')

/**
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
Expand Down Expand Up @@ -59,7 +60,12 @@ class DialRequest {

const tokenHolder = new FIFO()
tokens.forEach(token => tokenHolder.push(token))
const dialAbortControllers = this.addrs.map(() => new AbortController())
const dialAbortControllers = this.addrs.map(() => {
const controller = new AbortController()
setMaxListeners && setMaxListeners(Infinity, controller.signal)

return controller
})
let completedDials = 0

try {
Expand Down

0 comments on commit 34d4a51

Please sign in to comment.