-
-
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 4 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 |
---|---|---|
|
@@ -52,7 +52,7 @@ export class AttestationService { | |
// A validator should create and broadcast the attestation to the associated attestation subnet when either | ||
// (a) the validator has received a valid block from the expected block proposer for the assigned slot or | ||
// (b) one-third of the slot has transpired (SECONDS_PER_SLOT / 3 seconds after the start of slot) -- whichever comes first. | ||
await Promise.race([sleep(this.clock.msToSlot(slot + 1 / 3), signal), this.waitForBlockSlot(slot)]); | ||
await Promise.race([this.waitForBlockSlot(slot), sleep(this.clock.msToSlot(slot + 1 / 3), 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. Why is it necessary to change the order here? 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. It was not a necessity. It was changed to align with the text of the spec, which was placed as a comment 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. What do you mean the spec? Where does the spec specify the order of promises in javascript? |
||
this.metrics?.attesterStepCallProduceAttestation.observe(this.clock.secFromSlot(slot + 1 / 3)); | ||
|
||
// Beacon node's endpoint produceAttestationData return data is not dependant on committeeIndex. | ||
|
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.