Skip to content

fix(cache): origin range pull buffers the whole span in memory — OOM on multi-GB ranges #2065

Closed

Description

@thiras

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 peak at 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_total stayed 0 (metered only after a fetch completes — none did).
  • Trigger: one peer opening parallel range serves on multi-GB blobs, e.g. 4e302437… and 24823b38… at byte_offset≈2.4 GB, byte_len≈2.38 GB, 0607ea13… at byte_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):

  1. origin.fetch_range → the whole span as one Bytes (OriginRangeFetch::Ranged { data, .. })
  2. encode_verified_range → a second, span-sized buffer (Vec::with_capacity(fetch_len + 8), crates/bao-range/src/lib.rs)
  3. 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 of byte_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.

Activity

  1. self-assigned this
    on Sep 19, 2026
  2. added
    kind:bug
    prio:high
    rust
    area:node
    on Sep 19, 2026
  3. moved this from Backlog to In progress in deCDNon Sep 19, 2026
  4. moved this from In progress to Done in deCDNon Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:nodekind:bugprio:highrust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions