Skip to content

cache: drain-path hash mismatch leaves a persistent named tag — wrong-hash bytes are GC-unreclaimable (unbounded disk growth) #837

Closed

Description

@thiras

Surfaced by a full-repository review (2026-06-09). Sibling of #835 (same root cause family: the three wrong-hash commit/cleanup paths have drifted).

Finding

commit_buffered_bytes (crates/cache/src/engine.rs:1788-1823) commits via add_bytes(bytes).await, which resolves through iroh-blobs' AddProgress::with_tag() (iroh-blobs-0.101.0/src/api/blobs.rs:664) and creates a persistent named tag. On hash mismatch the code calls self.evict(actual) (correctly stops serving) but never deletes that named tag — so unlike the streaming path's drop(temp_tag), the bytes stay GC-protected forever.

Impact

A hostile origin returning small (≤ buffered_max_bytes, default 4 MiB) mismatched bodies on repeated requests grows on-disk usage without bound. The gc_bytes_reclaimed/pull_through_bytes amplification alert will not fire, because GC genuinely cannot reclaim these bytes.

Fix

On the drain-path mismatch, delete the named tag (tags API) alongside the logical evict so the bytes become GC-eligible, matching the streaming path's temp-tag-drop semantics. Preferably as part of a unified "reject + logical-evict + make-GC-eligible" helper shared by all three wrong-hash paths (see #835).

Related LOW noted in the same review: evict() does a blocking sync_all() directly on the async runtime and is invoked from the mismatch hot path (engine.rs:878-928, :1737, :1812) — worth moving to spawn_blocking when touching this code.

Refs

Activity

  1. added
    kind:bug
    prio:medium
    on Jun 9, 2026
  2. added
    kind:security
    on Jun 9, 2026
  3. github-actions commented on Jun 9, 2026

    @github-actions

    🎯 Triage report

    commit_buffered_bytes (engine.rs:1788-1823) uses add_bytes().await which resolves via AddProgress::with_tag() and creates a persistent named tag in iroh-blobs. Unlike the streaming path's TempTag (dropped on scope exit), this tag is never removed on hash mismatch — only self.evict(actual) is called. Wrong-hash bytes from the drain path are therefore permanently GC-protected and accumulate on disk indefinitely. A hostile origin can exhaust node storage by repeatedly sending small (≤4 MiB default) mismatched bodies, and the standard gc_bytes_reclaimed/pull_through_bytes amplification alert will not fire because GC genuinely cannot reclaim these bytes.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Incorrect resource lifecycle — named tag is never deleted, permanently blocking GC reclamation
    Labels security added Hostile-origin disk-exhaustion vector; existing bug+medium are correct and unchanged
    Coding agent Suitable Code location pinpointed (engine.rs:1788-1823), fix clearly described (delete named tag alongside evict()), success criteria explicit

    🔗 Similar issues

    💡 Notes and suggestions

    Root cause detail:
    add_bytes(bytes).await → AddProgress::with_tag() inserts a Tag entry into iroh-blobs' tag store. Without an explicit store.tags().delete(tag) the blob is permanently GC-protected regardless of sweep cadence. The streaming path avoids this because TempTag is dropped on scope exit; the buffered path has no equivalent automatic cleanup.

    Minimal fix (drain path only):
    Retrieve the tag value from the add_bytes result before the mismatch check, then delete it on the mismatch branch alongside self.evict(actual):

    // In commit_buffered_bytes hash-mismatch branch (~engine.rs:1812)
    // After: self.evict(actual).await?;
    // Add:
    self.blobs.tags().delete(committed_tag).await?;

    The exact tag handle depends on the AddProgress/add_bytes API surface — capture it from the outcome before the hash comparison.

    Preferred fix (unified helper, closes #835 and #837 together):
    Extract a reject_and_make_gc_eligible(hash, tag) helper called from all three wrong-hash arms:

    1. engine.rs:1676-1697 — streaming captured-error arm (cache: streaming-path captured-error partial import is never logically evicted — wrong-hash bytes serveable until next GC sweep #835)
    2. engine.rs:1716-1746 — streaming clean hash-mismatch arm
    3. engine.rs:1807-1820 — drain hash-mismatch arm (this issue)

    This is the approach the author recommends and would close the class of bugs.

    Secondary (LOW) — blocking I/O inside evict():
    evict() calls sync_all() synchronously at lines 878-928, 1737, and 1812; should be moved to spawn_blocking when this code is touched to avoid blocking a tokio thread-pool thread.

    Suggested test additions:

    • Trigger drain-path with body ≤ buffered_max_bytes and a mismatched hash
    • Assert engine.has(actual_hash) is false immediately after (no serving window)
    • Assert that after a GC sweep, disk usage returns to baseline (no GC-protected orphan tag)

    Monitoring note for operators: Because GC cannot reclaim these bytes, the standard amplification alert is silent. Until the fix lands, operators running high-traffic nodes with potentially hostile origins may want to monitor iroh-blobs tag-count growth as a secondary signal.

    Generated by Agentic Triage for issue #837 · sonnet46 649.2K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. self-assigned this
    on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:securityprio:medium

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions