fix(ext/node): do not exit worker thread when there is pending async op (#27378)

This change fixes the premature exit of worker threads when there are still
remaining pending ops.

This change reuses the idea of #22647 (unref'ing `op_worker_recv_message` in
worker threads if closeOnIdle specified) and uses
`web_worker.has_message_event_listener` check in the opposite way as
#22944. (Now we continue the worker when `has_message_event_listener` is
true instead of stopping it when `has_message_event_listener` is false.

closes #23061
closes #26154
This commit is contained in:
Yoshiya Hinosawa 2024-12-19 17:39:20 +09:00 committed by GitHub
parent 55d345baed
commit 350d9dce41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 49 additions and 38 deletions

View file

@ -21,7 +21,7 @@ import {
nodeWorkerThreadCloseCb,
refMessagePort,
serializeJsMessageData,
unrefPollForMessages,
unrefParentPort,
} from "ext:deno_web/13_message_port.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { notImplemented } from "ext:deno_node/_utils.ts";
@ -451,10 +451,10 @@ internals.__initWorkerThreads = (
parentPort.emit("close");
});
parentPort.unref = () => {
parentPort[unrefPollForMessages] = true;
parentPort[unrefParentPort] = true;
};
parentPort.ref = () => {
parentPort[unrefPollForMessages] = false;
parentPort[unrefParentPort] = false;
};
if (isWorkerThread) {