Skip to content

Commit b70fb43

Browse files
authored
fix: increase maxlisteners on event target (#1050)
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
1 parent ae21299 commit b70fb43

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/dialer/dial-request.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict'
22

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

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

6061
const tokenHolder = new FIFO()
6162
tokens.forEach(token => tokenHolder.push(token))
62-
const dialAbortControllers = this.addrs.map(() => new AbortController())
63+
const dialAbortControllers = this.addrs.map(() => {
64+
const controller = new AbortController()
65+
setMaxListeners && setMaxListeners(Infinity, controller.signal)
66+
67+
return controller
68+
})
6369
let completedDials = 0
6470

6571
try {

0 commit comments

Comments
 (0)