Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increase maxlisteners on event target #1050

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Changes from all commits
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
fix: increase maxlisteners on event target
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
commit 34d4a51c21a5313188e5243ee18293ac44c06c4e
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