Skip to content

fix(test): serve integration test leaks a ~57MB temp dir per run — 1,123 dirs / 62.5 GB took the machine to ENOSPC #361

Description

@MichaelTaylor3d

Task

dig-node's serve integration test creates a temp directory per run and never removes it. It
accumulated 1,123 directories totalling 62.5 GB in %LOCALAPPDATA%\Temp, which took the dev machine
to 81 MB free on a 1.9 TB disk and produced a machine-wide ENOSPC that stopped an unrelated lane
mid-build.

Make the test clean up after itself.

Measured

1,123 dirs  dig-node-serve-test-<pid>-<n>   62.47 GB   (~57 MB each)

Deleting them recovered the disk from 81 MB → 66.5 GB free.

The same Temp tree holds ~38,000 further leaked dirs from sibling tests, near-zero bytes each but real
filesystem clutter:

dirs bytes prefix
9,898 ~0 dig-tip*
6,832 ~0 dig-node-auth*
6,701 0.77 GB dig-node-test*
5,683 ~0 dig-node-custody*
3,659 0.01 GB dig-wallet-sup*
2,585 ~0 dig-wallet-rpc-authgate*
1,354 0.07 GB dig-wallet-svc*

dig-node-serve-test is the only one that matters for space; the rest matter because 50,000 entries
make every Temp scan slow and make the real leak hard to see. Fixing the shared helper likely fixes all
of them at once.

Why this is a defect and not housekeeping

It took down a machine. ENOSPC is a CLAUDE.md hard STOP (§1.6, §1.7): the lane that hit it correctly
refused to free space by deleting a sibling lane's target/, so it had to stop and hand back. Every Rust
lane on the machine was blocked until an orchestrator intervened.

It is also self-concealing: the leak grows fastest exactly when the test suite runs most, so it
surfaces during heavy development and looks like a build-cache problem. The first diagnosis here blamed
worktree target/ dirs — which totalled ~25 GB across six worktrees and were not the cause.

Likely shape of the fix

Use an RAII temp-dir guard (e.g. tempfile::TempDir) rather than a constructed path, so cleanup happens
on drop including on panic. Note the related trap already recorded in this repo: a cleanup placed
after an .await leaks on panic if anything catches it
— the guard must own the directory, not a
deferred cleanup step.

If a test deliberately preserves its dir on failure for diagnosis, that is legitimate — but it must then
be bounded (keep the last N, or delete on success) rather than unbounded.

Done condition

Run the serve integration suite twice and show the Temp dig-node-serve-test* count returns to its
pre-run value. A test that asserts its own cleanup is better than a manual check.

Scope

The temp-dir lifecycle in the test helpers. Do not widen into the tests' actual assertions.

Effort

Low-to-medium — one shared helper, but verify it covers the panic path, which is where this class
normally survives a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions