-
Notifications
You must be signed in to change notification settings - Fork 804
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
Detect if listener is already wrapped by once #3122
Conversation
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.
I prefer this solution over #3123 since it only change patch for add listener (whereas the other one modify the bind which is much more used).
@@ -177,6 +177,11 @@ implements ContextManager { | |||
) { | |||
const contextManager = this; | |||
return function (this: never, event: string, listener: Func<void>) { | |||
// @ts-expect-error listener is not a property of type Function but it is actually used by the onceWrapper in events.js | |||
if (typeof listener === 'function' && typeof listener.listener === 'function' && listener.name === 'bound onceWrapper') { |
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.
be aware that OTel context manager is likely not be the only one patching EventEmitter
. More or less any APM product and a lot other tools (e.g. zone.js - yes it's used by node.js apps not only browsers) patch this also.
Therefore you might have others between once
and on
.
You could rely on the single threaded nature of JS and set some inOnce
flag in ContextManager and check this one instead.
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.
You could rely on the single threaded nature of JS and set some inOnce flag in ContextManager and check this one instead.
Good idea. Opened a third PR #3132
I think I prefer #3133. Closing this but it can be reopened if someone disagrees. |
Fixes #2971
This is an alternative solution to #3123