fix(windows): end output streams before releasing owned handles

Settle local streams even when native handle release fails, retaining handle ownership and retry semantics until release succeeds.

Reviewed-PR: #3230
Co-authored-by: qorvr <330186599+qorvr@users.noreply.github.com>
This commit is contained in:
morlutoandqorvr committed 2026-10-14 16:10:46 +08:00
1 parent c482ddd6ad
commit dd1c879580
2 files changed
+46 -3

No files matched your search

+4 -2
View File
@@ -387,11 +387,13 @@ export class WindowsOwnedProcess extends EventEmitter {
if (this.#closed) return;
if (this.#timer !== undefined) clearTimeout(this.#timer);
this.#clearBlockedWake();
this.#authority.call("process_close", [this.#handle]);
this.#closed = true;
this.stdin?.destroy();
if (!this.stdout.destroyed) this.stdout.end();
if (!this.stderr.destroyed) this.stderr.end();
// End local streams before releasing the native handle. If release fails,
// the retained job can be retried without leaving output streams open.
this.#authority.call("process_close", [this.#handle]);
this.#closed = true;
this.#settle?.();
this.emit("close", this.exitCode, null);
}