Skip to content

test: harness memory footprint is unbounded per fuzz worker, not just in difftest #193

Closed

Description

@scttfrdmn

Fixed in CI by GOMEMLIMIT=768MiB on the fuzz-smoke job (commit 2e8e3cc). That is the right fix for the runner, but it treats a symptom whose cause is in the harness, and the cause will resurface anywhere else the same shape appears.

What happened

go test -fuzz runs one worker process per CPU. Each is an independent Go runtime that sizes its heap against total machine memory, because none of them knows the others exist. On a 4-CPU runner that is 4× over-commitment before any test code runs.

FuzzOperationSequence allocates hard — each iteration is a real read-modify-write over a real HTTP endpoint — so four workers reached 6 GB RSS in four seconds and the cgroup OOM-killed one. Verified in a 7 GB container: oom_kill 1, signal: killed.

The failure is actively misleading. go test reports:

fuzzing process hung or terminated unexpectedly while minimizing: EOF
Failing input written to testdata/fuzz/FuzzOperationSequence/ed66669b703735e8

It names an input and writes it to the corpus. Every input written this way replays green — the hash differs on each run because it is whichever input the dead worker happened to hold. Anyone debugging this from the log alone will chase an input that is not the problem. The first occurrence was written off as runner preemption on the strength of exit 143 and a shutdown-signal message, both of which are consistent with an OOM-induced runner health-check failure.

What is worth doing beyond the CI knob

  1. A measured per-iteration allocation budget for the difftest fuzz target. Peak RSS tracked ~3.7× GOMEMLIMIT across a sweep (384MiB → 1.4 GB, 768MiB → 2.9 GB, 1536MiB → 5.7 GB). That ratio is stable enough to assert on, and an assertion would catch a future change that makes an iteration 10× hungrier.

  2. Bound the shared emulator's object accumulation. testaws.Shared is process-lifetime with an in-memory state manager, and vfsPair allocates a fresh bucket per factory call — Shrink calls it hundreds of times per counterexample. Measured leak is modest (~28 KB/iteration, plateauing around 91 MB heap / 355 MB Sys at 6000 iterations) so this is not the OOM cause, but it is monotonic within a run and nothing sweeps it.

  3. A note in internal/testaws and the difftest fuzz target that the runtime does not know about its sibling workers, so any target using a real endpoint needs a memory limit. This is the part that generalizes: the next such target will hit it too.

Why 768MiB

The memory was garbage the collector had no pressure signal to reclaim, not live data — so the cap costs nothing and returns the time that was going into page thrash. Same 60s budget, exact CI command, coverage-guided:

execs new interesting peak RSS result
unbounded 1443 3 7.2 GB OOM-killed ~40s
GOMEMLIMIT=768MiB 24679 48 3.2 GB exit 0

17× more of the input space explored, because the workers stopped thrashing.

Activity

  1. added
    type: testing
    priority: medium
    area: core
    on Aug 2, 2026
  2. added
    effort: medium
    on Aug 3, 2026
  3. scttfrdmn commented on Aug 5, 2026

    @scttfrdmn
    OwnerAuthor

    Measured this before writing anything, and the premise needs revising: most of the memory this issue is about is not the harness's. Details in #362 — 82% of the per-iteration allocation is one site in production code, cargoship/pkg/aws/s3/transporter.go:63's 64 MiB sync.Pool buffer, which the runtime clears at every GC and which every sub-32-MiB PutObject therefore re-allocates. Flipping EnableCargoShipOptimization off over the same 500 difftest iterations takes runtime.Sys from 649.9 MiB to 76.3 MiB, an 8.5× difference, with HeapAlloc flat at 30.2 MiB in both.

    That reorders the three asks here.

    Ask 1 — the per-iteration allocation budget — should not be written yet, and this is the useful correction. A budget asserted today would encode #362's cost as the harness's expected footprint. When #362 lands the assertion fails, and the natural reading of that failure is "the budget needs raising" rather than "the thing it was measuring is gone". Land #362 first, then set the budget against what remains.

    The measurement itself is in hand, and it is smaller than the RSS numbers above suggest: 1.9 MiB of TotalAlloc per iteration for a 6-op program with two flushes, one read and a reopen. The ~3.7× GOMEMLIMIT ratio this issue proposes asserting on is not a property of the harness at all — it is #362's feedback loop. Halving the limit multiplied total allocation by 4.75× with CargoShip on and changed nothing with it off:

    cargo=on   GOMEMLIMIT=768MiB   totalAlloc=751MiB   numGC=4    heapSys=531MiB
    cargo=on   GOMEMLIMIT=384MiB   totalAlloc=3570MiB  numGC=28   heapSys=499MiB
    cargo=off  GOMEMLIMIT=768MiB   totalAlloc=285MiB   numGC=12   heapSys=67MiB
    cargo=off  GOMEMLIMIT=384MiB   totalAlloc=285MiB   numGC=12   heapSys=67MiB
    

    A ratio that inverts under the fix is not a stable thing to assert on. Per-iteration TotalAlloc is, because it doesn't depend on GC timing.

    Ask 2 — bound the shared emulator's object accumulation — is smaller than stated and not worth doing on its own. This issue estimates ~28 KB/iteration accumulating to ~91 MB heap at 6000 iterations. Sampling HeapAlloc after two forced GCs every 100 iterations, out to 1000:

    n=0      heapAlloc=2.9MiB   live=25434
    n=100    heapAlloc=29.6MiB  live=26845
    n=500    heapAlloc=30.2MiB  live=29031
    n=1000   heapAlloc=31.0MiB  live=31613
    

    Flat after the first hundred: 1.4 MiB of growth across 900 iterations, and 6179 net live objects. The emulator does retain every object — 500 objects in one bucket after 500 factory calls, confirmed by listing — but they total 0.3 MiB, because the fuzz decoder caps a write at 4096 bytes. Monotonic, yes; a memory problem, no. Worth a sentence in SharedServer's doc rather than a sweeper.

    Ask 3 — the note that a fuzz worker's runtime cannot see its siblings — stands as filed and is the part that generalizes. It's also the part that would have prevented the misdiagnosis: the first occurrence was written off as runner preemption, and the reason a GOMEMLIMIT was needed at all is now known to be mostly #362 rather than the target's own appetite.

    Suggest this issue stays open for ask 3 plus the doc sentence from ask 2, and that the budget waits on #362. If you'd rather have the budget now with a comment naming #362 as the reason for the number, that's a defensible call too — it just means editing the number twice.

  4. scttfrdmn commented on Aug 5, 2026

    @scttfrdmn
    OwnerAuthor

    #362 has landed (#363), so the blocker on the per-iteration allocation budget is gone. Re-measured on the merged code, 300 shrink iterations through vfsPair:

    GOMEMLIMIT totalAlloc per iteration GCs heapAlloc sys
    768 MiB 1859.3 MiB 6.20 MiB 11 468.8 MiB 589.5 MiB
    384 MiB 1862.1 MiB 6.21 MiB 28 352.7 MiB 380.7 MiB

    Total allocation is now flat across the limit — 0.15% apart. Before #362 the same comparison was 751 MiB / 4 GCs at 768 MiB against 3570 MiB / 28 GCs at 384 MiB, a 4.75× penalty for tightening the limit, because a sync.Pool holding a 64 MiB buffer is drained at every collection. That inversion is what made the budget unwritable: a number recorded then would have encoded the transporter's cost as the harness's expected footprint, and the drop when #362 landed would have read as "the budget is stale, raise it."

    So the assertion this issue asks for is now well-defined, and the stable quantity to assert on is per-iteration TotalAlloc, not a GOMEMLIMIT ratio. The ratio is a property of the collector's response to a limit, not of the harness; it moved 4.75× → 1.00× on a change that touched no harness code. Per-iteration allocation moved 1.9 MiB → 6.2 MiB over the same period for reasons that are harness-side (the vfs write path grew read-modify-write), which is exactly what a budget should be sensitive to.

    Note the 384 MiB run is now strictly better on every retained-memory number — heapAlloc 353 vs 469 MiB, sys 381 vs 590 MiB — at the cost of 17 more GCs across 300 iterations. That is worth a separate look at the GOMEMLIMIT: 768MiB in ci.yml:230, whose long comment justifies the value against the pre-#362 behavior. Not changing it here: the comment's reasoning ("this job stopped dying") was about peak RSS under parallel fuzz workers, which this single-threaded measurement does not speak to.

    Asks 2 and 3 are unchanged from my earlier comment — ask 2 is real but small (1.4 MiB of heap growth across 900 iterations, not ~91 MB) and wants a doc sentence on SharedServer rather than a sweeper; ask 3 stands as filed.

  5. scttfrdmn commented on Aug 5, 2026

    @scttfrdmn
    OwnerAuthor

    All three asks beyond the CI knob are implemented in #364. The first one changed shape once it could be measured, and that is worth recording here because the change is in this issue's own premise.

    Ask 1 — the allocation budget does not assert the ratio this issue proposed

    The proposal was to assert peak RSS as a ratio of GOMEMLIMIT, on the strength of ~3.7× holding across a sweep. That ratio is not a property of the harness:

    GOMEMLIMIT=768MiB GOMEMLIMIT=384MiB apart
    before #362 751 MiB 3570 MiB 4.75×
    after #362 1859 MiB 1862 MiB 0.15%

    300 difftest iterations, same code, same machine. The mechanism is that a sync.Pool holding a 64 MiB buffer is cleared at every GC cycle, so a tighter limit bought more collections and therefore more total allocation. #362 deleted the upload path holding that pool and the inversion went with it.

    This is why the budget was deliberately deferred until #362 landed: written before it, the assertion would have encoded the transporter's cost as the harness's expected footprint, and it would have been a ratio that moved 4.75× → 1.00× on a change touching no harness code.

    TestPerIterationAllocationBudget asserts per-iteration TotalAlloc instead — the invariant underneath. It is what actually rises when an iteration gets hungrier, and it is insensitive to GOMEMLIMIT and to worker count. Measured 6.3 MiB for a program of writes and reads and 7.1 MiB for one dominated by flush/reopen pairs, within 1% with -race on and off. Ceiling set at 16 MiB — the regression worth catching is a 10×, since that is what OOMs a worker.

    The input shape it measures against is the load-bearing choice. Measured on the committed seed corpus, an iteration is 0.31 MiB — 20× less — because those entries are four operations with 64-byte payloads while the decoder admits 64 operations with 4 KiB payloads at offsets up to 1 MiB. A budget measured on the corpus would assert a number the fuzzer never touches and pass forever while the shapes it actually generates got arbitrarily more expensive. So the test builds worst-shaped inputs from the decoder's own constants, which also means a change to what the fuzzer can generate changes what this budgets.

    Verified by mutation rather than by predicting the signature: a 1 MiB allocation per write takes both cases to ~30 MiB and fails both subtests.

    Ask 2 — retention is bounded, and it is bounded by an actual delete

    Measured in both directions, 64 KiB objects, heap after forced GC:

    +100 +200 +400
    with the delete +0.0 MiB +0.0 MiB +0.1 MiB
    without +0.2 MiB +0.5 MiB +1.1 MiB

    ~2.8 KB per iteration, monotonic, for the life of the process. The delete goes in the cleanup the factory already returns to the shrinker, after Close rather than before — deleting first would have the subject reading a key that vanished under it.

    Confirming what this issue already said: this is not the OOM cause and the megabytes are not the reason to fix it. The reason is that "grows without bound, but slowly" is not a property worth having in the component every other test trusts to be inert, and the plateau observed at 6000 iterations is the allocator's, not a bound anything guarantees.

    Ask 3 — the note, in both places

    internal/testaws's package doc gets a # Memory, under a fuzz target section and FuzzOperationSequence gets a pointer to it: go test -fuzz runs one worker process per CPU, each an independent runtime sizing its heap against total machine memory with no knowledge of its siblings, so a 4-CPU runner over-commits by 4× before any test code runs. Both record the misleading failure mode, since that is the part that costs someone a day — the kill reports as "fuzzing process hung or terminated unexpectedly", names an input, writes it to the corpus, and that input replays green.

    SharedServer's own doc now states the retention property where the type is defined rather than only where one caller happens to sweep it: nothing sweeps what callers store, that is the cost of the process lifetime, and a caller writing per iteration has to delete per iteration.

    One thing deliberately not changed

    ci.yml:230 still sets GOMEMLIMIT: 768MiB. Post-#362 the 384 MiB run is strictly better on retained memory locally — heapAlloc 353 vs 469 MiB, sys 381 vs 590 MiB — at the cost of 17 more GCs. That is not enough to move the CI value, because the knee measurement this issue documents (768MiB → 2.9 GB peak, 24679 execs) was taken with four parallel fuzz worker processes and a single-threaded local run cannot speak to it. Worth its own measurement if anyone wants the headroom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreeffort: mediumpriority: mediumtype: testing

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions