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

test: reduce flakiness of test-esm-loader-hooks #49105

Merged
merged 3 commits into from
Aug 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/es-module/test-esm-loader-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,19 @@ describe('Loader hooks', { concurrency: true }, () => {
`
import {MessageChannel} from 'node:worker_threads';
import {register} from 'node:module';
import {setTimeout} from 'node:timers/promises';
const {port1, port2} = new MessageChannel();
port1.on('message', (msg) => {
console.log('message', msg);
});
const result = register(
${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize-port.mjs'))},
${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize-port.mjs'))},
{data: port2, transferList: [port2]},
);
console.log('register', result);

await import('node:os');
await setTimeout(99); // delay to limit flakiness
Copy link
Member

Choose a reason for hiding this comment

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

isnt this just hiding a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, race conditions are inherent to cross thread communication I think

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't a user have to do this too? If so, this feels like a legit bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've known this since we started working on off-threading the loader hooks, it's documented here:

node/doc/api/esm.md

Lines 740 to 743 in 6ad8318

Hooks are run in a separate thread, isolated from the main. That means it is a
different [realm](https://tc39.es/ecma262/#realm). The hooks thread may be
terminated by the main thread at any time, so do not depend on asynchronous
operations (like `console.log`) to complete.

Copy link
Member

@JakobJingleheimer JakobJingleheimer Aug 11, 2023

Choose a reason for hiding this comment

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

OH! Sorry, this is for a console log. Sorry, yes.

Wouldn't it be better to use something not console log then?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe process._rawDebug or fs.writeFileSync(1?

port1.close();
`,
]);
Expand Down