From 72199303d899b8ddf2ff46ed11bd513ed9cc47e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 22 Jul 2022 18:07:20 +0200 Subject: fix: Child.unref() unrefs stdio streams properly (#15275) --- runtime/js/40_spawn.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'runtime/js') diff --git a/runtime/js/40_spawn.js b/runtime/js/40_spawn.js index a00b8cfda..87db84f4b 100644 --- a/runtime/js/40_spawn.js +++ b/runtime/js/40_spawn.js @@ -75,6 +75,7 @@ class Child { #rid; #waitPromiseId; + #unrefed = false; #pid; get pid() { @@ -132,6 +133,7 @@ this.#stdoutRid = stdoutRid; this.#stdout = readableStreamForRid(stdoutRid, (promise) => { this.#stdoutPromiseId = promise[promiseIdSymbol]; + if (this.#unrefed) core.unrefOp(this.#stdoutPromiseId); }); } @@ -139,6 +141,7 @@ this.#stderrRid = stderrRid; this.#stderr = readableStreamForRid(stderrRid, (promise) => { this.#stderrPromiseId = promise[promiseIdSymbol]; + if (this.#unrefed) core.unrefOp(this.#stderrPromiseId); }); } @@ -204,12 +207,14 @@ } ref() { + this.#unrefed = false; core.refOp(this.#waitPromiseId); if (this.#stdoutPromiseId) core.refOp(this.#stdoutPromiseId); if (this.#stderrPromiseId) core.refOp(this.#stderrPromiseId); } unref() { + this.#unrefed = true; core.unrefOp(this.#waitPromiseId); if (this.#stdoutPromiseId) core.unrefOp(this.#stdoutPromiseId); if (this.#stderrPromiseId) core.unrefOp(this.#stderrPromiseId); -- cgit v1.2.3