Files
OmniRoute/scripts/dev/run-standalone.mjs
diegosouzapw 4b6d6c7670 fix(docker): honor OMNIROUTE_MEMORY_MB heap limit in standalone launcher (#2939)
The Docker image bakes NODE_OPTIONS=--max-old-space-size=256, and the standalone
launcher (scripts/dev/run-standalone.mjs, the Docker CMD) spawned 'node
server.js' without overriding it — so the server inherited the 256 MB cap and
OOMed randomly under load or with a large SQLite DB. `omniroute serve` already
honored OMNIROUTE_MEMORY_MB but the Docker path did not.

Add a shared resolveMaxOldSpaceMb() helper (OMNIROUTE_MEMORY_MB, default 512,
clamped [64,16384]) and have the launcher append --max-old-space-size to the
child NODE_OPTIONS (a trailing flag wins, overriding the baked 256 without
clobbering other flags). Update the .env.example doc to reflect the 512 default.
2026-05-31 09:15:55 -03:00

27 lines
948 B
JavaScript

#!/usr/bin/env node
import {
resolveRuntimePorts,
withRuntimePortEnv,
resolveMaxOldSpaceMb,
spawnWithForwardedSignals,
} from "../build/runtime-env.mjs";
import { bootstrapEnv } from "../build/bootstrap-env.mjs";
const env = bootstrapEnv();
const runtimePorts = resolveRuntimePorts(env);
const childEnv = withRuntimePortEnv(env, runtimePorts);
// #2939: the Docker image bakes NODE_OPTIONS=--max-old-space-size=256, which OOMs
// under load / large SQLite DBs. Honor OMNIROUTE_MEMORY_MB (default 512), the same
// knob `omniroute serve` uses. A trailing --max-old-space-size wins, so this
// overrides the baked 256 without clobbering any other NODE_OPTIONS flags.
const maxOldSpaceMb = resolveMaxOldSpaceMb(childEnv.OMNIROUTE_MEMORY_MB);
childEnv.NODE_OPTIONS =
`${childEnv.NODE_OPTIONS || ""} --max-old-space-size=${maxOldSpaceMb}`.trim();
spawnWithForwardedSignals("node", ["server.js"], {
stdio: "inherit",
env: childEnv,
});