-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Expose setMaxListeners
property on AbortSignal
#54758
Comments
The right avenue to purse this change is WHATWG (the group maintaining those standards). From past experience, any time we deviate from the standard we cause more harm than good. |
But isn't So this would try to explore a way to get closer to the standard, not further away. |
By that logic, another alternative suggestion here could be: Alternative suggestion: set no default listener count limit on
|
@jasnell you added the warning in @KhafraDev you added those getters/setters in What do you folks think? |
node shouldn't have implemented warnings or interop with EventEmitter in the first place, but we absolutely shouldn't deviate further from the spec and other implementations |
@nodejs/web-standards what do you all think? |
Pinging @lucacasonato too (hope you don't mind). |
Agree with @KhafraDev. If anything this should be a setter function you import from |
I agree. We should not extend the standard API with non-standard extensions. |
+1 (no nonstandard extensions). I do like the alternative suggestion tho (#54758 (comment)) |
I agree with the alternative suggestion as well |
@jasnell are you ok for #54758 (comment)? |
Just so we're clear - we are within our rights from the spec's PoV to emit a warning on more than N listeners (or really anything, warnings aren't considered observable). We've clarified that several times with WHATWG explicitly to make sure. |
I actually prefer that warning remain in place as it has actually proved useful in a couple of cases. But I won't block removing it. |
You can also use import { setMaxListeners } from 'node:events'
setMaxListeners(10, new EventEmitter())
setMaxListeners(10, new BroadcastChannel())
setMaxListeners(10, new AbortSignal()) |
@kettanaito assuming I'm writing a package that will never run outside of node - which was the whole trigger for this issue - I'm not, and I was looking for an isomorphic way of doing this 😅 That said, this has been sitting for a while and I'm not sure what the conclusion really was - with support for both directions, there didn't seem to be a final verdict. Would you at this point accept a PR with my suggestion of setting Users in search of potential performance problems or memory leaks could still enable it, but it would probably reduce friction a lot for people who want to write isomorphic code. |
You can use the somewhat new
|
@KhafraDev this is something I could do as an end user, but as a library author I cannot advise all my users to turn off that warning - they might want to rely on it in different places, while not wanting to get warnings from dependency internals. As a library author I can also not depend on the default warning number being 10 and try to split up my 15 subscribers into e.g. 7 and 8 - the user could have changed their default to 5. The only viable options is that as a library author I
The ugly workaround I'm currently using is iterating |
@phryneas I think that library is simple to create, as I think most bundlers allow for browsers alternates, so that some code will execute in Node.js but never in the browsers, making it isomorphic. |
So we've gone from a library with a single (and rather short) published code file to a library with 3 published code files (2 environment-specific ones, one shared), an I might as well publish this on npm as Honestly, this feels wrong - and I'm sorry that I voice my frustration here, but I feel like it needs to be said. This is not how things should end up when node starts picking up web standards - the need for these workarounds should go down, not up :( |
@phryneas even if we removed the warning, this will hardly trickle down to past releases. I'm not even sure we should make it semver-minor or not. Anyhow, would you like to send a PR to remove the warning limit? I don't see much opposition in keeping it. |
That's still a lot better than doing nothing :)
Will do! |
This change sets the default `kMaxEventTargetListeners` property for `AbortSignal` instances to 0, disabling the check per default, to enable users to write isomorphic library code. If desirable, the max event target listeners check can still be enabled for individual `AbortSignal` instances by calling `setMaxListeners` on them. Refs: nodejs#54758
This change sets the default `kMaxEventTargetListeners` property for `AbortSignal` instances to 0, disabling the check per default, to enable users to write isomorphic library code. If desirable, the max event target listeners check can still be enabled for individual `AbortSignal` instances by calling `setMaxListeners` on them. Refs: nodejs#54758
This change sets the default `kMaxEventTargetListeners` property for `AbortSignal` instances to 0, disabling the check per default, to enable users to write isomorphic library code. If desirable, the max event target listeners check can still be enabled for individual `AbortSignal` instances by calling `setMaxListeners` on them. Refs: nodejs#54758
This change sets the default `kMaxEventTargetListeners` property for `AbortSignal` instances to 0, disabling the check per default, to enable users to write isomorphic library code. If desirable, the max event target listeners check can still be enabled for individual `AbortSignal` instances by calling `setMaxListeners` on them. Refs: #54758 PR-URL: #55816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This change sets the default `kMaxEventTargetListeners` property for `AbortSignal` instances to 0, disabling the check per default, to enable users to write isomorphic library code. If desirable, the max event target listeners check can still be enabled for individual `AbortSignal` instances by calling `setMaxListeners` on them. Refs: #54758 PR-URL: #55816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
What is the problem this feature will solve?
Right now, there is no stable way to change the
maxEventTargetListeners
of anAbortSignal
without importing fromnode:events
.This makes it impossible to write isomorphic library code that adds more than the default 10 event listeners, without having to resort to workarounds such as
This relies on the
events.maxEventTargetListeners
symbol description, which, to my knowledge is not part of any public API and could change at any time.What is the feature you are proposing to solve the problem?
Add a
AbortSignal.setMaxListeners
instance method so isomorphic code could do something likeWhat alternatives have you considered?
Alternatively, if this is not an option as it could pollute a spec-defined object with additional properties, use
Symbol.for
instead ofnew Symbol
forkMaxEventTargetListeners
and make that a part of the official api.I would be willing to implement this feature.
The text was updated successfully, but these errors were encountered: