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

worker: remove redundant function call to setupPortReferencing in setupChild #22298

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ function setupChild(evalScript) {
if (message.type === messageTypes.LOAD_SCRIPT) {
const { filename, doEval, workerData, publicPort, hasStdin } = message;
publicWorker.parentPort = publicPort;
setupPortReferencing(publicPort, publicPort, 'message');
publicWorker.workerData = workerData;

if (!hasStdin)
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-worker-parent-port-ref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Flags: --experimental-worker
'use strict';
const assert = require('assert');
const common = require('../common');
const { isMainThread, parentPort, Worker } = require('worker_threads');

// This test makes sure that we manipulate the references of
// `parentPort` correctly so that any worker threads will
// automatically exit when there are no any other references.
{
if (isMainThread) {
const worker = new Worker(__filename);

worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}), 1);

worker.on('online', common.mustCall());
} else {
const messageCallback = () => {};
parentPort.on('message', messageCallback);
// The thread won't exit if we don't make the 'message' listener off.
parentPort.off('message', messageCallback);
}
}