fix(shared): prune Bun directory fds before spawn

This commit is contained in:
YeonGyu-Kim
2026-05-30 23:51:35 +09:00
parent 1b9e667486
commit f50cfb8984
7 changed files with 263 additions and 16 deletions
+9 -2
View File
@@ -5,6 +5,7 @@ import {
type SpawnSyncOptions as NodeSpawnSyncOptions,
} from "node:child_process"
import { Readable, Writable } from "node:stream"
import { pruneLeakedDirectoryFileDescriptorsBeforeSpawn } from "./spawn-fd-pruner"
type AnyRecord = Record<string, unknown>
type StdioMode = "pipe" | "inherit" | "ignore"
@@ -190,7 +191,10 @@ export function spawn(options: SpawnOptions & { cmd: string[] }): SpawnedProcess
export function spawn(cmdOrOpts: unknown, opts?: unknown): SpawnedProcess {
const { cmd, opts: options } = resolveCommand(cmdOrOpts, opts)
const bun = getBunRuntime()
if (bun) return bun.spawn(cmd, options)
if (bun) {
pruneLeakedDirectoryFileDescriptorsBeforeSpawn()
return bun.spawn(cmd, options)
}
const [bin, ...args] = cmd
if (bin === undefined) {
@@ -207,7 +211,10 @@ export function spawnSync(options: SpawnOptions & { cmd: string[] }): SpawnSyncR
export function spawnSync(cmdOrOpts: unknown, opts?: unknown): SpawnSyncResult {
const { cmd, opts: options } = resolveCommand(cmdOrOpts, opts)
const bun = getBunRuntime()
if (bun) return bun.spawnSync(cmd, options)
if (bun) {
pruneLeakedDirectoryFileDescriptorsBeforeSpawn()
return bun.spawnSync(cmd, options)
}
const [bin, ...args] = cmd
if (bin === undefined) {