Skip to content

Commit 5df923b

Browse files
t3dotggclaude
andcommitted
fix(dev): the dev runner owns its child's process group
Signalling process group 0 could reach the shell that launched the runner. Start vp in its own group so teardown, SIGTERM to the runner, and the memory limit all stop the whole dev tree. Reject a negative T3CODE_DEV_MEMORY_LIMIT_GB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 05bb0ec commit 5df923b

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

‎scripts/dev-runner.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,9 @@ export const runDevRunnerWithInput = Effect.fn("dev-runner.runDevRunnerWithInput
887887
env,
888888
extendEnv: false,
889889
shell: spawnCommand.shell,
890-
// Keep Vite+ in the same process group so terminal signals (Ctrl+C)
891-
// reach it directly. Effect defaults to detached: true on non-Windows,
892-
// which would put the runner in a new group and require manual forwarding.
893-
detached: false,
890+
// Its own process group: teardown signals the whole group, because vp
891+
// does not pass SIGTERM on to Vite and the server.
892+
detached: true,
894893
forceKillAfter: "1500 millis",
895894
}).pipe(
896895
Effect.mapError(
@@ -926,6 +925,8 @@ export const runDevRunnerWithInput = Effect.fn("dev-runner.runDevRunnerWithInput
926925
}
927926
});
928927

928+
const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
929+
929930
const devRunnerCli = Command.make("dev-runner", {
930931
mode: Argument.Literals("mode", DEV_RUNNER_MODES).pipe(
931932
Argument.withDescription("Development mode to run."),
@@ -992,11 +993,16 @@ const devRunnerCli = Command.make("dev-runner", {
992993
Flag.withDefault(false),
993994
),
994995
memoryLimitGb: Flag.Int("memory-limit-gb").pipe(
995-
Flag.withSchema(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
996+
Flag.withSchema(NonNegativeInt),
996997
Flag.withDescription(
997998
"Stop the dev server when it and its child processes use more than this many GiB of RAM plus swap (equivalent to T3CODE_DEV_MEMORY_LIMIT_GB). Defaults to half of RAM, at most 16. 0 turns it off. Linux only.",
998999
),
999-
Flag.withFallbackConfig(optionalIntegerConfig("T3CODE_DEV_MEMORY_LIMIT_GB")),
1000+
Flag.withFallbackConfig(
1001+
Config.schema(NonNegativeInt, "T3CODE_DEV_MEMORY_LIMIT_GB").pipe(
1002+
Config.option,
1003+
Config.map(Option.getOrUndefined),
1004+
),
1005+
),
10001006
),
10011007
runArgs: Argument.String("run-arg").pipe(
10021008
Argument.withDescription("Additional Vite+ run args (pass after `--`)."),

‎scripts/lib/dev-memory-limit.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ const readProcessTreeBytes = Effect.fn("DevRunner.readProcessTreeBytes")(functio
7777
});
7878

7979
/**
80-
* Samples this process and its descendants every 30 seconds. Once they hold
81-
* more than `limitBytes` of RAM plus swap, it logs why and sends SIGTERM to
82-
* this process group. Linux only; elsewhere it never completes.
80+
* Samples this process and its descendants every 30 seconds and fails once
81+
* they hold more than `limitBytes` of RAM plus swap. Linux only; elsewhere it
82+
* never completes.
8383
*/
8484
export const enforceDevMemoryLimit = Effect.fn("DevRunner.enforceDevMemoryLimit")(function* (
8585
limitBytes: number,
@@ -89,11 +89,7 @@ export const enforceDevMemoryLimit = Effect.fn("DevRunner.enforceDevMemoryLimit"
8989
yield* Effect.sleep("30 seconds");
9090
const usedBytes = yield* readProcessTreeBytes(process.pid);
9191
if (usedBytes > limitBytes) {
92-
const error = new DevRunnerMemoryLimitError({ usedBytes, limitBytes });
93-
yield* Effect.logError(error.message);
94-
// vp does not pass SIGTERM to its tasks, so stopping only the child would orphan Vite and the server.
95-
process.kill(0, "SIGTERM");
96-
return yield* error;
92+
return yield* new DevRunnerMemoryLimitError({ usedBytes, limitBytes });
9793
}
9894
}
9995
});

0 commit comments

Comments
 (0)