mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-08 08:12:20 +03:00
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.
40 lines
1.6 KiB
TypeScript
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);
|
|
});
|