[Internal tests] Close MessageChannel port to prevent leak (#26357)
Node's MessageChannel implementation will leak if you don't explicitly close the port. This updates the enqueueTask function we use in our internal testing helpers to close the port once it's no longer needed.
Andrew Clark committed
Mar 9, 2023 at 11:20 UTC
39d4b9365718932da29fa05ad8debb351b616498
1 file changed
+4
-1
packages/internal-test-utils/enqueueTask.js
+4
-1
@@ -11,6 +11,9 @@ const {MessageChannel} = require('node:worker_threads');
11
12
export default function enqueueTask(task: () => void): void {
13
const channel = new MessageChannel();
14
- channel.port1.onmessage = task;
14
+ channel.port1.onmessage = () => {
15
+ channel.port1.close();
16
+ task();
17
+ };
18
channel.port2.postMessage(undefined);
19
}