Repository navigation
Description
Summary
CacheEngine::pull_through_range buffers the entire requested span in memory — twice — with no size cap and no concurrency bound. A client issuing a few multi-GB range requests against a partially-held blob OOM-kills the node. The testnet node bcl (16 GB RAM) was OOM-killed 10× in 24 h this way.
Evidence (testnet, 2026-09-19)
decdn-node.service: Failed with result 'oom-kill'…14.6G memory peak, 3.9G memory swap peakat 04:44, 14:39, 15:04, 16:10 UTC (12 restarts in 24 h on bcl vs 2 on fra1/lon1).- Not a leak: host memory flat at ~0.67 GB, then 4.5 GB (16:09:30) → 10 GB (16:10:00) → killed 16:10:09.
decdn_cache_origin_fetches_total{instance="bcl"}increased only in the 2-minute windows immediately before each kill (14:40, 15:04, 16:10) and at no other time 04:30–16:20. ~4 fetches started in the last window;decdn_cache_pull_through_bytes_totalstayed 0 (metered only after a fetch completes — none did).- Trigger: one peer opening parallel range serves on multi-GB blobs, e.g.
4e302437…and24823b38…atbyte_offset≈2.4 GB, byte_len≈2.38 GB,0607ea13…atbyte_len≈1.35 GB.decdn_streams_active{direction="inbound"}1 → 8 while egress was ~6 MB/s — memory grew far faster than the wire.
Mechanism
try_range_pull_through (crates/node/src/handlers/client/fill.rs) passes the client's full (byte_offset, byte_len) to pull_through_range, and range_pull_attempt (crates/cache/src/engine.rs):
origin.fetch_range→ the whole span as oneBytes(OriginRangeFetch::Ranged { data, .. })encode_verified_range→ a second, span-sized buffer (Vec::with_capacity(fetch_len + 8),crates/bao-range/src/lib.rs)import_bao_bytes(hash, ranges, encoded)→ hands the whole encoded buffer to iroh-blobs
≈ 2× span resident per request, unbounded. Two 2.38 GB spans + one 1.35 GB ≈ 12–13 GB → OOM.
Every other byte path is bounded: the serve export (export_bao_range_stream, 32-item channel, #1132), the miss-leg encoder (ENCODE_CHANNEL_CAP = 8), and whole-blob pull_through (drains ≤ buffered_max_bytes, 4 MiB, otherwise streams). The origin range pull is the one path #1132's "memory independent of blob size" guarantee does not cover.
A 2 GB node (fra1/lon1) dies on the first such request.
Fix direction
- Fix: window the range pull — fetch / verify / import the aligned span in bounded chunk-group windows (a few MiB each) in a loop, so peak memory is
O(window)regardless ofbyte_len. Also bound concurrent range pulls. - Test: a range pull of a span ≫ window must hold peak buffered bytes at ~window (e.g. an origin double that asserts it is never asked for more than a window per
fetch_range).
Also observed (separate)
bcl crash-looped ~122× with Failed with result 'exit-code' around 00:58 UTC before the 04:29 redeploy — not OOM, not investigated.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
fix(cache): harden windowed range pulls per PR review (#2065)
fix(cache): window origin range pulls to bound memory (#2065) (#2066)