Repository navigation
v0.4.2-beta — Bound nuclei response sizes and auto-tune GOMEMLIMIT to prevent OOM
Pre-releaseFixes the scanner OOM-killed at the container 2 GiB cap reported in #274.
Problem
During a scan of ~106 endpoints the nuclei process was killed twice by the kernel OOM killer (CONSTRAINT_MEMCG) after reaching the container's 2 GiB limit. Heap climbed from baseline to ~2 GiB within ~5 s — dozens of simultaneous connections to a single CDN edge with 1.5–4.7 MiB unread Recv-Q each, plus Go heap anon-rss:2 GiB. Model: heap ≈ 1–1.5 × concurrency × response-size-read (nuclei default 10 MiB) stacked with cgroup-accounted TCP buffers.
Fix (#275)
Two complementary, deployment-independent fixes:
-
Per-response caps as scan-policy knobs —
scan_policies.response_size_read/_save(nullable,>0,CHECK) via forward migration0002_add_scan_policy_response_limits.sql(post-beta freeze,0001_init.sqluntouched). Plumbedtypes.ScanOptions→store.ScanPolicy→validateScanPolicy/overlayScanPolicy→runner.buildArgs(-response-size-read/-save, omitted ⇒ nuclei default 10 MiB/1 MiB) → bundle snapshot → SPA (modal/table, placeholders10485760/1048576). Loweringreadtoward 1 MiB linearly shrinks worst-case heap. -
Automatic
GOMEMLIMITon the scanner node —internal/scanner/memlimit.goreads cgroup limit from/sys/fs/cgroup/memory.max(v2) thenmemory/memory.limit_in_bytes(v1) (treatingmax/>1 PiB/sentinel9223372036854771712as unlimited), derivesGOMEMLIMIT ≈75%of cap (truncated to MiB, floored at 64 MiB, documented assumption for non-tiny cgroups), leaves 25% for kernel TCP buffers/RSS slack. ExplicitGOMEMLIMITwins (runtime already honored at startup). Applied viaGOMEMLIMITenv (inherited bynuclei/naabu) anddebug.SetMemoryLimitso GC pressure replaces kills.
Tests: TestBuildArgsResponseSize, TestOverlayScanPolicy (response sizes), TestValidateScanPolicy, TestParseGOMEMLIMIT (TiB/MiB/GiB/KiB/B, case-insensitive), TestParseCgroupLimitValue, TestGomemlimitFromCgroup (floor/truncation).
Operational notes
- Existing
GOMEMLIMIT=1500MiBworkaround still honored (explicit wins). - Existing policies get nuclei defaults until edited; set
response_size_readto1048576(1 MiB) to bound CDN streaming. - No
tcp_rmemchange; headroom is inGOMEMLIMIT.
Merged
Full changelog: v0.4.1-beta...v0.4.2-beta