Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-process-group-nonzero-exit-cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform-node-shared": patch
---

Honor `forceKillAfter` during scope release after a command leader exits with a non-zero code, so surviving descendants that ignore the termination signal are forcefully killed.
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ const make = Effect.gen(function*() {
if (exited) {
const [code] = yield* Deferred.await(exitSignal)
if (code !== 0 && Predicate.isNotNull(code)) {
yield* Effect.ignore(killProcessGroup(cmd, childProcess, cmd.options.killSignal ?? "SIGTERM"))
yield* Effect.ignore(terminateProcessGroup(cmd, childProcess, exitSignal, cmd.options))
} else if (isReferenced && process.platform !== "win32" && cmd.options.detached !== false) {
yield* Effect.ignore(terminateProcessGroup(cmd, childProcess, exitSignal, cmd.options))
}
Expand Down
16 changes: 16 additions & 0 deletions packages/platform/node-shared/test/NodeChildProcessSpawner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ describe.skipIf(process.platform === "win32")("process group cleanup", () => {
assert.strictEqual(yield* fs.readFileString(marker), "exited")
}).pipe(Effect.scoped, Effect.provide(NodeServices)))

it.live("scope release force kills descendants after the leader exits with a non-zero code", () =>
Effect.gen(function*() {
const { descendantPid, handle, marker, scope } = yield* startProcessGroup("ignore-signal", {
stdin: "pipe",
forceKillAfter: "200 millis"
})
yield* Effect.addFinalizer(() => killDescendant(descendantPid))

yield* Stream.run(Stream.make(new TextEncoder().encode("exit 1\n")), handle.stdin)
assert.strictEqual(yield* handle.exitCode, 1)

yield* Scope.close(scope, Exit.void).pipe(liveTimeout(2_000))

yield* assertHeartbeatStopped(marker)
}).pipe(Effect.scoped, Effect.provide(NodeServices)))

it.live("scope release cleans descendants after the leader is killed externally", () =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (role === "leader") {
spawn(process.execPath, [process.argv[1], "descendant", mode, marker], {
stdio: ["ignore", "inherit", "inherit"]
})
process.stdin.once("data", () => process.exit(0))
process.stdin.once("data", (data) => process.exit(data.toString().trim() === "exit 1" ? 1 : 0))
setInterval(() => {}, 1_000)
} else {
if (mode === "exit-on-signal") {
Expand Down
Loading