Files
OmniRoute/tests/unit/runtime-env-max-old-space.test.ts
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

40 lines
1.6 KiB
TypeScript

/**
* Issue #2939 — random OOM in Docker. The image bakes
* NODE_OPTIONS=--max-old-space-size=256, and the standalone launcher
* (`scripts/dev/run-standalone.mjs`, the Docker CMD) did not honor
* OMNIROUTE_MEMORY_MB, so the server child inherited the 256 MB cap and OOMed
* under load / large SQLite DBs.
*
* `resolveMaxOldSpaceMb` is the shared heap-ceiling resolver the launcher now
* uses (mirroring `omniroute serve`): OMNIROUTE_MEMORY_MB clamped to [64, 16384],
* default 512.
*/
import test from "node:test";
import assert from "node:assert/strict";
const { resolveMaxOldSpaceMb } = await import("../../scripts/build/runtime-env.mjs");
test("#2939 default is 512 when unset/invalid", () => {
assert.equal(resolveMaxOldSpaceMb(undefined), 512);
assert.equal(resolveMaxOldSpaceMb(null), 512);
assert.equal(resolveMaxOldSpaceMb(""), 512);
assert.equal(resolveMaxOldSpaceMb("abc"), 512);
});
test("#2939 honors a valid OMNIROUTE_MEMORY_MB (string or number)", () => {
assert.equal(resolveMaxOldSpaceMb("1024"), 1024);
assert.equal(resolveMaxOldSpaceMb(2048), 2048);
assert.equal(resolveMaxOldSpaceMb("256"), 256);
});
test("#2939 clamps out-of-range values to the default", () => {
assert.equal(resolveMaxOldSpaceMb("32"), 512, "below 64 → default");
assert.equal(resolveMaxOldSpaceMb("99999"), 512, "above 16384 → default");
assert.equal(resolveMaxOldSpaceMb("64"), 64, "lower bound inclusive");
assert.equal(resolveMaxOldSpaceMb("16384"), 16384, "upper bound inclusive");
});
test("#2939 a custom fallback is respected", () => {
assert.equal(resolveMaxOldSpaceMb(undefined, 1024), 1024);
});