Skip to content
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

[fix] make test/create-websocket-stream.test.js compatible with domains #2126

Merged

Conversation

mvduin
Copy link
Contributor

@mvduin mvduin commented Mar 9, 2023

Fix a failure in test/create-websocket-stream.test.js if the node:domain module is loaded (e.g. due to NODE_OPTIONS in environment).

The cause of the failure was that installing an 'uncaughtException' event handler on process will cause node:domain to prepend its own handler for the same event, which confused the test.

Fixes: #2124

Fix a failure in test/create-websocket-stream.test.js if the node:domain
module is loaded (e.g. due to NODE_OPTIONS in environment).

The cause of the failure was that installing an 'uncaughtException'
event handler on process will cause node:domain to prepend its own
handler for the same event, which confused the test.

Fixes: websockets#2124

const [listener] = process.listeners('uncaughtException');
const listener = process.listeners('uncaughtException').pop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The domain added 'uncaughtException' listener is always prepended and kept, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is prepended when you add the first listener for 'uncaughtException' and removed when you remove the last listener for it (excluding the one from domain)

> let foo = () => {}
> let bar = () => {}
> process.listenerCount('uncaughtException')
0
> process.on('uncaughtException', foo); process.listenerCount('uncaughtException')
2
> process.on('uncaughtException', bar); process.listenerCount('uncaughtException')
3
> process.off('uncaughtException', foo); process.listenerCount('uncaughtException')
2
> process.off('uncaughtException', bar); process.listenerCount('uncaughtException')
0

@lpinca lpinca merged commit b4b9d5a into websockets:master Mar 9, 2023
@lpinca
Copy link
Member

lpinca commented Mar 9, 2023

Thank you.

@mvduin mvduin deleted the fix/stream-test-with-domains branch March 10, 2023 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create-websocket-stream.test.js fails if the domain module is loaded
2 participants