-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Bug: MessageChannel in Scheduler prevents Jest test from exiting #26608
Comments
I'm seeing the same issue during some experiments with Mocha testing. The suggested fix works for me. I will produce a minimal repro if that's considered desirable. @victor-homyakov Are you aware of any kind of workaround for this? |
The workaround is to use patched MessageChannel in JSDom, something like const MessageChannelOriginal = require('node:worker_threads').MessageChannel;
class MessageChannel {
constructor() {
const channel = new MessageChannelOriginal();
// Allow the thread to exit if this is the only active handle in the event system
if (channel.port1.unref) {
channel.port1.unref();
}
this.channel = channel;
}
get port1() {
return this.channel.port1;
}
// ...
}
window.MessageChannel = MessageChannel; |
Thank you very much for the workaround! In practice I found that simply const MessageChannelOriginal = global.MessageChannel
global.MessageChannel = class {
constructor () {
const channel = new MessageChannelOriginal()
this.port1 = new Proxy(channel.port1, {
set (port1, prop, value) {
const result = Reflect.set(port1, prop, value)
if (prop === 'onmessage') {
port1.unref()
}
return result
}
})
this.port2 = channel.port2
}
} Alternatively, as I happen to be using Mocha, I found that the |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump, this is still an issue for us. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump |
Bump |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump |
Bump |
React version: any
Scheduler version: any up to current (0.23.0)
Steps To Reproduce
setImmediate
function.MessageChannel
MessageChannel is not defined jsdom/jsdom#2448. IfMessageChannel
is required to test some important functionality, one can add an implementation from Node.js as recommended in comment MessageChannel is not defined jsdom/jsdom#2448 (comment)Link to code example: https://github.com/victor-homyakov/scheduler-jest-jsdom-example
The current behavior
Test is endless. Jest won't stop. Console shows a message
Running Jest with
--detectOpenHandles
outputs:The expected behavior
Code at
react/packages/scheduler/src/forks/Scheduler.js
Line 621 in 5426af3
unref
the handle:The text was updated successfully, but these errors were encountered: