Skip to content

v0.4.2-beta — Bound nuclei response sizes and auto-tune GOMEMLIMIT to prevent OOM

Pre-release
Pre-release

Choose a tag to compare

@Nikolasel Nikolasel released this 24 Aug 20:45
· 108 commits to main since this release
Immutable release. Only release title and notes can be modified.
ce1c5ea

Fixes 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 migration 0002_add_scan_policy_response_limits.sql (post-beta freeze, 0001_init.sql untouched). Plumbed types.ScanOptions → store.ScanPolicy → validateScanPolicy/overlayScanPolicy → runner.buildArgs (-response-size-read/-save, omitted ⇒ nuclei default 10 MiB/1 MiB) → bundle snapshot → SPA (modal/table, placeholders 10485760/1048576). Lowering read toward 1 MiB linearly shrinks worst-case heap.

  • Automatic GOMEMLIMIT on the scanner node — internal/scanner/memlimit.go reads cgroup limit from /sys/fs/cgroup/memory.max (v2) then memory/memory.limit_in_bytes (v1) (treating max/>1 PiB/sentinel 9223372036854771712 as unlimited), derives GOMEMLIMIT ≈75% of cap (truncated to MiB, floored at 64 MiB, documented assumption for non-tiny cgroups), leaves 25% for kernel TCP buffers/RSS slack. Explicit GOMEMLIMIT wins (runtime already honored at startup). Applied via GOMEMLIMIT env (inherited by nuclei/naabu) and debug.SetMemoryLimit so 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=1500MiB workaround still honored (explicit wins).
  • Existing policies get nuclei defaults until edited; set response_size_read to 1048576 (1 MiB) to bound CDN streaming.
  • No tcp_rmem change; headroom is in GOMEMLIMIT.

Merged

  • #275 fix(scanner): bound nuclei response sizes and auto-tune GOMEMLIMIT to prevent OOM (#274)

Full changelog: v0.4.1-beta...v0.4.2-beta