From 0b8d7d1d4b068df46a14895b2f55c00781bd1eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 16 Apr 2024 00:06:39 +0100 Subject: fix(ext/node): panic on 'worker_threads.receiveMessageOnPort' (#23386) Closes https://github.com/denoland/deno/issues/23362 Previously we were panicking if there was a pending read on a port and `receiveMessageOnPort` was called. This is now fixed by cancelling the pending read, trying to read a message and resuming reading in a loop. --- ext/node/polyfills/worker_threads.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ext/node/polyfills/worker_threads.ts') diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 323095206..f61e7e3e3 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -17,6 +17,7 @@ import { MessagePort, MessagePortIdSymbol, MessagePortPrototype, + MessagePortReceiveMessageOnPortSymbol, nodeWorkerThreadCloseCb, refMessagePort, serializeJsMessageData, @@ -441,6 +442,7 @@ export function receiveMessageOnPort(port: MessagePort): object | undefined { err["code"] = "ERR_INVALID_ARG_TYPE"; throw err; } + port[MessagePortReceiveMessageOnPortSymbol] = true; const data = op_message_port_recv_message_sync(port[MessagePortIdSymbol]); if (data === null) return undefined; return { message: deserializeJsMessageData(data)[0] }; -- cgit v1.2.3