mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 02:22:14 +00:00
fix: MaxListenersExceeded warning (#1297)
Where we create signals that are passed down the stack, increase the max listeners to prevent warnings in the console.
This commit is contained in:
parent
ba56c64662
commit
627b8bf87c
@ -20,6 +20,7 @@ import type { Connection } from '@libp2p/interface-connection'
|
||||
import type { RelayConfig } from '../index.js'
|
||||
import { abortableDuplex } from 'abortable-iterator'
|
||||
import { TimeoutController } from 'timeout-abort-controller'
|
||||
import { setMaxListeners } from 'events'
|
||||
|
||||
const log = logger('libp2p:circuit')
|
||||
|
||||
@ -64,6 +65,11 @@ export class Circuit implements Transport, Initializable {
|
||||
const { connection, stream } = data
|
||||
const controller = new TimeoutController(this._init.hop.timeout)
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, controller.signal)
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
const source = abortableDuplex(stream, controller.signal)
|
||||
const streamHandler = new StreamHandler({
|
||||
|
@ -2,6 +2,7 @@ import type { PeerInfo } from '@libp2p/interface-peer-info'
|
||||
import { logger } from '@libp2p/logger'
|
||||
import type { Components } from '@libp2p/components'
|
||||
import { TimeoutController } from 'timeout-abort-controller'
|
||||
import { setMaxListeners } from 'events'
|
||||
|
||||
const log = logger('libp2p:dialer:auto-dialer')
|
||||
|
||||
@ -44,6 +45,11 @@ export class AutoDialer {
|
||||
|
||||
const controller = new TimeoutController(this.dialTimeout)
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, controller.signal)
|
||||
} catch {}
|
||||
|
||||
void this.components.getConnectionManager().openConnection(peer.id, {
|
||||
signal: controller.signal
|
||||
})
|
||||
|
@ -331,6 +331,11 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
||||
this.connectOnStartupController?.clear()
|
||||
this.connectOnStartupController = new TimeoutController(this.startupReconnectTimeout)
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, this.connectOnStartupController.signal)
|
||||
} catch {}
|
||||
|
||||
await Promise.all(
|
||||
keepAlivePeers.map(async peer => {
|
||||
await this.openConnection(peer, {
|
||||
@ -510,6 +515,11 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
||||
if (options?.signal == null) {
|
||||
timeoutController = new TimeoutController(this.dialTimeout)
|
||||
options.signal = timeoutController.signal
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -14,6 +14,7 @@ import { abortableDuplex } from 'abortable-iterator'
|
||||
import { pipe } from 'it-pipe'
|
||||
import first from 'it-first'
|
||||
import { TimeoutController } from 'timeout-abort-controller'
|
||||
import { setMaxListeners } from 'events'
|
||||
|
||||
const log = logger('libp2p:fetch')
|
||||
|
||||
@ -99,6 +100,11 @@ export class FetchService implements Startable {
|
||||
if (signal == null) {
|
||||
timeoutController = new TimeoutController(this.init.timeout)
|
||||
signal = timeoutController.signal
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -27,6 +27,7 @@ import { TimeoutController } from 'timeout-abort-controller'
|
||||
import type { AbortOptions } from '@libp2p/interfaces'
|
||||
import { abortableDuplex } from 'abortable-iterator'
|
||||
import type { Duplex } from 'it-stream-types'
|
||||
import { setMaxListeners } from 'events'
|
||||
|
||||
const log = logger('libp2p:identify')
|
||||
|
||||
@ -164,8 +165,13 @@ export class IdentifyService implements Startable {
|
||||
const protocols = await this.components.getPeerStore().protoBook.get(this.components.getPeerId())
|
||||
|
||||
const pushes = connections.map(async connection => {
|
||||
const timeoutController = new TimeoutController(this.init.timeout)
|
||||
let stream: Stream | undefined
|
||||
const timeoutController = new TimeoutController(this.init.timeout)
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
stream = await connection.newStream([this.identifyPushProtocolStr], {
|
||||
@ -234,6 +240,11 @@ export class IdentifyService implements Startable {
|
||||
if (signal == null) {
|
||||
timeoutController = new TimeoutController(this.init.timeout)
|
||||
signal = timeoutController.signal
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
try {
|
||||
@ -374,6 +385,11 @@ export class IdentifyService implements Startable {
|
||||
const { connection, stream } = data
|
||||
const timeoutController = new TimeoutController(this.init.timeout)
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
const publicKey = this.components.getPeerId().publicKey ?? new Uint8Array(0)
|
||||
const peerData = await this.components.getPeerStore().get(this.components.getPeerId())
|
||||
@ -425,6 +441,11 @@ export class IdentifyService implements Startable {
|
||||
const { connection, stream } = data
|
||||
const timeoutController = new TimeoutController(this.init.timeout)
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
|
||||
let message: Identify | undefined
|
||||
try {
|
||||
// make stream abortable
|
||||
|
@ -14,6 +14,7 @@ import type { AbortOptions } from '@libp2p/interfaces'
|
||||
import { abortableDuplex } from 'abortable-iterator'
|
||||
import { TimeoutController } from 'timeout-abort-controller'
|
||||
import type { Stream } from '@libp2p/interface-connection'
|
||||
import { setMaxListeners } from 'events'
|
||||
|
||||
const log = logger('libp2p:ping')
|
||||
|
||||
@ -90,6 +91,11 @@ export class PingService implements Startable {
|
||||
if (signal == null) {
|
||||
timeoutController = new TimeoutController(this.init.timeout)
|
||||
signal = timeoutController.signal
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -20,6 +20,7 @@ import type { Registrar } from '@libp2p/interface-registrar'
|
||||
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
|
||||
import { TimeoutController } from 'timeout-abort-controller'
|
||||
import { abortableDuplex } from 'abortable-iterator'
|
||||
import { setMaxListeners } from 'events'
|
||||
|
||||
const log = logger('libp2p:upgrader')
|
||||
|
||||
@ -133,6 +134,11 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
||||
|
||||
const timeoutController = new TimeoutController(this.inboundUpgradeTimeout)
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, timeoutController.signal)
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
const abortableStream = abortableDuplex(maConn, timeoutController.signal)
|
||||
maConn.source = abortableStream.source
|
||||
@ -407,6 +413,11 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
||||
|
||||
controller = new TimeoutController(30000)
|
||||
options.signal = controller.signal
|
||||
|
||||
try {
|
||||
// fails on node < 15.4
|
||||
setMaxListeners?.(Infinity, controller.signal)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
let { stream, protocol } = await mss.select(protocols, options)
|
||||
|
Loading…
x
Reference in New Issue
Block a user