Skip to content

Commit

Permalink
[Internal tests] Close MessageChannel port to prevent leak
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Mar 9, 2023
1 parent 3706edb commit 4da5568
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/internal-test-utils/enqueueTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const {MessageChannel} = require('node:worker_threads');

export default function enqueueTask(task: () => void): void {
const channel = new MessageChannel();
channel.port1.onmessage = task;
channel.port1.onmessage = () => {
channel.port1.close();
task();
};
channel.port2.postMessage(undefined);
}

0 comments on commit 4da5568

Please sign in to comment.