Skip to content

ninja recompact crash cascade on Windows: 150 minidumps + 0xC00000FD stack overflow per bash test --cpp run #2857

Description

@zackees

Summary

bash test --cpp on Windows triggers a deterministic 150-minidump crash cascade during perform_ninja_maintenance() (which runs ninja -t recompact on the meson-quick .ninja_deps file). The cascade ends in a 0xC00000FD stack overflow. Although the maintenance step says "(non-fatal)" and the build continues, the crash spam:

  1. Floods 150+ lines of CI/Stop-hook output, making real failures unreadable.
  2. Confuses the meson test runner's output-stream parser, causing it to report phantom test failures (Some tests failed (0/0 tests in 78.98s) with the per-test "failure details" containing only MESSAGE logs from successful test runs).
  3. Generates 150 minidump files on disk per run that nobody is going to look at.

Reproduces on every bash test --cpp run on Windows.

Symptom

From two consecutive Stop-hook bash test --cpp runs (this PR session, master @ b1d4fe98df):

1.25 [MESON] Configuring build (compiler probes may take 20-30s)...
3.63 [MESON] 🔧 Performing periodic Ninja dependency database maintenance...
3.67 ninja: warning: premature end of file; recovering
3.67 ninja: error: exception: 0xC0000005
3.74 ninja: warning: minidump created: ninja: error: exception: 0xC0000005
3.82 ninja: warning: minidump created: ninja: error: exception: 0xC0000005
… (≈150 more identical lines, ~70 ms apart) …
15.89 ninja: error: exception: 0xC00000FD     ← stack overflow
16.29 [BUILD] Building FastLED engine (quick mode)...   ← build resumes

After ~12 s of crash spam, the maintenance "completes with warnings (non-fatal)" and the build proceeds. The test execution downstream then either succeeds (most tests pass) or — worse — the runner misreports a phantom failure:

80.20 [MESON] ⚠️  Compilation errors detected - showing diagnostic output:
… 3 blocks tagged [ERROR in <file>] that contain only -Wunused-parameter / -Wtautological-undefined-compare / -Wsign-compare *warnings* …
80.21 [MESON] ❌ Some tests failed (0/0 tests in 78.98s)
80.22 --- fl_codec ---
… 30 lines of MESSAGE: log output from successful codec validation …

Note the (0/0 tests in 78.98s) — zero passed, zero run, but one "failed". That's a runner-output-parsing artifact downstream of the ninja-crash output corruption, not a real test failure in fl_codec. (bash test fl_codec in isolation passes.)

Where in our code

ci/meson/build_config.py:351-413, function perform_ninja_maintenance():

def perform_ninja_maintenance(build_dir: Path) -> bool:
    …
    _ts_print("[MESON] 🔧 Performing periodic Ninja dependency database maintenance...")
    try:
        repair_proc = RunningProcess(
            ["ninja", "-C", str(build_dir), "-t", "recompact"],
            timeout=60,
            …
        )
        returncode = repair_proc.wait(echo=True)
        if returncode == 0:
            …
            marker_file.touch()    # ← never gets touched, so we re-run next time
            return True
        _ts_print("[MESON] ⚠️  Maintenance completed with warnings (non-fatal)", file=sys.stderr)
        return True
    …

Called from ci/util/meson_example_runner.py:524-525.

The marker_file (.ninja_deps_maintenance) is only touch()-ed when returncode == 0. Since this crashes every time on Windows, the marker is never created, so the maintenance runs on every invocation, recreating the crash cascade every time.

Root cause

This is upstream-ninja's bug, not ours, but we are the trigger.

  1. ninja -t recompact access-violation crashes when the .ninja_deps file is in a specific corrupted state. The premature end of file; recovering message comes from ninja's deps-log parser when the file has a valid header but a truncated record (probably written during an earlier ungraceful test-process termination).

  2. Ninja's crash handler is recursive on Windows. Each 0xC0000005 triggers minidump created, which crashes again writing the next minidump, etc., ~150 times until stack overflow (0xC00000FD).

  3. Our installed ninja is 1.13.0.git.kitware.jobserver-pipe-1 (Kitware fork with meson's jobserver-pipe extension), installed via the ninja PyPI wheel that pins this build. Kitware/ninja has GitHub issues disabled, so we can't file upstream there. The crash-handler recursion bug might be present in mainline ninja-build/ninja too — worth confirming, but not on the critical path for fixing our user pain.

Reproduction (isolation attempts so far)

I tried minimal reproductions with the same ninja binary in /tmp/ninja-repro/:

.ninja_deps state ninja -t recompact result
Missing clean: no output, exit 0
Empty bad deps log signature or version; starting over → failed recompaction: No such file or directory (clean)
Truncated header (# ninjadeps\x04\x00\x00\x00) same as empty
Random garbage (200 bytes of /dev/urandom) same as empty

None of these produce premature end of file or the crash. The trigger requires a .ninja_deps with a valid header + at least one valid record + partial second record — i.e. a real-world file that was being written to when a previous build process was killed mid-recompact or mid-build. Synthesizing this byte-exact requires reading ninja's DepsLog::Load() parser line-by-line; I didn't get that far before deciding the FastLED-side workaround is sufficient.

Proposed fix (FastLED side)

Two changes to ci/meson/build_config.py:perform_ninja_maintenance():

  1. Pre-emptive cleanup: before invoking ninja -t recompact, if .ninja_deps exists, rename it to .ninja_deps.bak. If recompact crashes, the build proceeds with a fresh deps log; the next build's ninja generates a clean deps log from scratch. This avoids the corrupt-state read entirely.

  2. Touch the marker on failure too, with a longer cooldown (e.g. 6 hours instead of 24 h), so a deterministic crash doesn't re-trigger on every invocation. Currently a Windows-side crash re-runs maintenance every time bash test --cpp is called, generating fresh 150-minidump cascades.

Sketch:

def perform_ninja_maintenance(build_dir: Path) -> bool:
    marker_file = build_dir / ".ninja_deps_maintenance"
    # … existing 24h-skip check unchanged …

    deps_file = build_dir / ".ninja_deps"
    deps_bak  = build_dir / ".ninja_deps.bak"
    if deps_file.exists():
        try:
            if deps_bak.exists():
                deps_bak.unlink()
            deps_file.rename(deps_bak)   # quarantine; ninja recompact will recreate
        except OSError:
            pass

    _ts_print("[MESON] 🔧 Performing periodic Ninja dependency database maintenance...")
    # … repair_proc as before …

    # Touch marker on success OR on non-fatal failure — avoids re-triggering
    # the crash cascade on every invocation when recompact is broken on this host.
    try:
        marker_file.touch()
    except (OSError, IOError):
        pass

    if returncode == 0:
        _ts_print("[MESON] ✓ Dependency database maintenance completed successfully")
    else:
        _ts_print("[MESON] ⚠️  Maintenance completed with warnings (non-fatal)", file=sys.stderr)
    return True

The deps_file.rename() is the actual functional fix. The marker change is to stop multiplying user-visible noise.

Bonus: clean up the minidumps

Each crash cascade writes ~150 ninja_*.dmp files to the build_dir (totalling tens of MB). They serve no purpose — they're all the same crash. A periodic cleanup of build_dir/**/*.dmp older than 1 hour would prevent disk-space bleed from accumulating these. Not blocking the fix above.

Acceptance criteria

  • bash test --cpp on Windows runs without 0xC0000005/0xC00000FD ninja minidump spam.
  • If recompact does fail, only one ⚠️ Maintenance completed with warnings line is emitted, then the build proceeds without the 150-line cascade.
  • The phantom fl_codec-style "test failure" disappears (downstream effect — the meson runner's output parser stops seeing ninja crash output mixed into compile output).

Out of scope

  • Upstream ninja-build/Kitware-ninja bugs: the access-violation in recompact and the recursive crash-handler. Those need separate filings against the ninja project once isolated.
  • The bash test --cpp "phantom fl_codec failure" — fixing this issue should make it go away. If it persists, file a follow-up issue against ci/meson/streaming_runner.py output-parser.

Found while investigating Stop-hook noise on #2822 (Docker decommission).

Activity

  1. moved this from Triage to Done in FastLED Trackeron Jun 6, 2026
  2. zackees commented on Jun 6, 2026

    @zackees
    MemberAuthor

    Root cause is upstream ninja, not zccache

    Quick triage after this issue was filed:

    • Not zccache. zccache wraps the compiler invocation and writes the .d depfile; ninja then parses that depfile and writes its own records into .ninja_deps. zccache never touches .ninja_deps itself. The zccache-session.log confirms this — only compile-side state, no deps-log writes.
    • Upstream ninja heap-OOB bug. DepsLog::Load() bounds-checks the dependency node IDs in each deps record but does not check the target out_id before calling UpdateDeps(out_id, deps), which then grows deps_ to out_id + 1 slots while leaving nodes_ at its original size. After Load() "recovers" from the partial trailing record, the invariant deps_.size() <= nodes_.size() is broken. Recompact() then iterates 0..deps_.size() and dereferences nodes_[old_id] -- heap OOB read, 0xC0000005 on Windows.
    • Cascade. The SEH __except + CreateWin32MiniDump path then re-enters the AV from inside MiniDumpWriteDump/dbghelp (which touches the same corrupt memory while walking the thread stack), producing ~150 minidumps before the thread stack overflows (0xC00000FD). The minidump writer should be gated against re-entry.

    Filed upstream: ninja-build/ninja#2787 with the analysis, code refs, and the FastLED workaround link.

    PR #2860 is therefore the right thing to keep on our side — it is a workaround (quarantine .ninja_deps before recompact + touch marker on failure), not a fix, but the actual fix needs to land in ninja-build/ninja. Closing this once #2860 merges; will track upstream progress separately if needed.

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions