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 synchronization between main thread and worker #14541

Merged
merged 10 commits into from May 22, 2022
13 changes: 8 additions & 5 deletions eslint/babel-eslint-parser/src/client.cjs
Expand Up @@ -60,19 +60,22 @@ exports.WorkerClient = class WorkerClient extends Client {
{ env: WorkerClient.#worker_threads.SHARE_ENV },
);

#signal = new Int32Array(new SharedArrayBuffer(4));

constructor() {
super((action, payload) => {
this.#signal[0] = 0;
// We create a new SharedArrayBuffer every time rather than reusing
// the same one, otherwise sometimes its contents get corrupted and
// Atomics.wait wakes up too early.
// https://github.com/babel/babel/pull/14541
const signal = new Int32Array(new SharedArrayBuffer(8));

const subChannel = new WorkerClient.#worker_threads.MessageChannel();

this.#worker.postMessage(
{ signal: this.#signal, port: subChannel.port1, action, payload },
{ signal, port: subChannel.port1, action, payload },
[subChannel.port1],
);

Atomics.wait(this.#signal, 0, 0);
Atomics.wait(signal, 0, 0);
const { message } = WorkerClient.#worker_threads.receiveMessageOnPort(
subChannel.port2,
);
Expand Down
6 changes: 5 additions & 1 deletion scripts/integration-tests/e2e-babel.sh
Expand Up @@ -33,6 +33,10 @@ startLocalRegistry "$PWD"/scripts/integration-tests/verdaccio-config.yml
node "$PWD"/scripts/integration-tests/utils/bump-babel-dependencies.js

# Build and test
YARN_ENABLE_IMMUTABLE_INSTALLS=false make -j test-ci
YARN_ENABLE_IMMUTABLE_INSTALLS=false make -j build-standalone-ci
for i in {1..50}; do
echo "RUN NUMBER $i"
BABEL_ENV=test yarn jest --maxWorkers=4 --ci
done
nicolo-ribaudo marked this conversation as resolved.
Show resolved Hide resolved

cleanup