Skip to content

Commit 4da5568

Browse files
committed
[Internal tests] Close MessageChannel port to prevent leak
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.
1 parent 3706edb commit 4da5568

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/internal-test-utils/enqueueTask.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const {MessageChannel} = require('node:worker_threads');
1111

1212
export default function enqueueTask(task: () => void): void {
1313
const channel = new MessageChannel();
14-
channel.port1.onmessage = task;
14+
channel.port1.onmessage = () => {
15+
channel.port1.close();
16+
task();
17+
};
1518
channel.port2.postMessage(undefined);
1619
}

0 commit comments

Comments
 (0)