-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
Preventing MaxListenersExceededWarning #4421
Changes from all commits
ebdbb50
7802a2a
d86bb68
72f211f
ccd11c1
ea7ef2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import {setMaxListeners} from "node:events"; | ||
import {Connection} from "libp2p"; | ||
import {HandlerProps} from "libp2p/src/registrar"; | ||
import LibP2p from "libp2p"; | ||
|
@@ -71,6 +72,9 @@ export class ReqResp implements IReqResp { | |
|
||
async start(): Promise<void> { | ||
this.controller = new AbortController(); | ||
dapplion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// We set infinity to prevent MaxListenersExceededWarning which get logged when listeners > 10 | ||
// Since it is perfectly fine to have listeners > 10 | ||
setMaxListeners(Infinity, this.controller.signal); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Responsible for the warning observed in the trace:
|
||
for (const [method, version, encoding] of protocolsSupported) { | ||
await this.libp2p.handle( | ||
formatProtocolId(method, version, encoding), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import {setMaxListeners} from "node:events"; | ||
import LibP2p from "libp2p"; | ||
import {Registry} from "prom-client"; | ||
|
||
|
@@ -118,6 +119,9 @@ export class BeaconNode { | |
metricsRegistries = [], | ||
}: IBeaconNodeInitModules): Promise<T> { | ||
const controller = new AbortController(); | ||
// We set infinity to prevent MaxListenersExceededWarning which get logged when listeners > 10 | ||
// Since it is perfectly fine to have listeners > 10 | ||
setMaxListeners(Infinity, controller.signal); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you commit as comment the stack trace proving that this very specific event emitter gets more that 10 listeners? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The signal here was what was passed down and triggered this:
|
||
const signal = controller.signal; | ||
|
||
// start db if not already started | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,10 @@ export class Validator { | |
} | ||
|
||
const emitter = new ValidatorEventEmitter(); | ||
// Validator event emitter can have more than 10 listeners in a normal course of operation | ||
// We set infinity to prevent MaxListenersExceededWarning which get logged when listeners > 10 | ||
emitter.setMaxListeners(Infinity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add proof with stack trace that this event listener triggers warnings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already responded to the diff in the comment here |
||
|
||
const chainHeaderTracker = new ChainHeaderTracker(logger, api, emitter); | ||
|
||
this.blockProposingService = new BlockProposingService(config, loggerVc, api, clock, validatorStore, metrics, { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shame we have to introduce a nodejs specific api here.
Later we can pass down a signal from the top-level beacon node and avoid creating a new signal here.