Skip to content

fix(ci): prevent macOS 26 ASan startup hangs #3642

Closed

Description

@zackees

Context

GitHub's macos-latest label migrated from macos-15-arm64 to
macos-26-arm64. Since that migration, FastLED's macOS unit and example
workflows compile successfully but hang when starting dynamically loaded
test/example libraries.

Strong A/B evidence:

The workflow, streaming executor, dynamic loader, and runner had no source
changes between the last green commit and the first failing commit.

The shared failure is in ci/meson/streaming.py:

  1. Ninja prints Linking target <library> before the link operation has
    completed.
  2. stream_compile_only() treats that status line as successful completion.
  3. It immediately invokes on_test_compiled().
  4. A worker starts runner <test>.dylib or
    example_runner <example>.dylib.
  5. On macOS 26, dlopen() can hang while ld64/lld is still writing the
    Mach-O library.
  6. The runner watchdog is installed after dlopen(), so it cannot diagnose
    or terminate this hang.
  7. The Python process timeout kills workers in 600-second batches until the
    enclosing workflow reaches its 30- or 45-minute timeout.

Both workflows pass --no-parallel, but the streaming path uses raw
os.cpu_count() and launches three workers anyway. This makes the race more
likely and means the command-line option does not provide its documented
behavior.

Raising workflow timeouts or pinning macos-15 would only mask the unsafe
link/load coordination.

Proposal

Make compilation and dynamic-library execution distinct phases:

  1. stream_compile_only() should collect linked test/example paths without
    executing callbacks from Ninja's pre-link status lines.
  2. Wait for the Meson/Ninja process to finish successfully.
  3. Complete post-link mtime stabilization.
  4. Only then submit CompileOnlyResult.compiled_tests to the execution pool.
  5. Never run collected artifacts when compilation fails.
  6. Use ci.util.cpu_count.cpu_count() for the streaming worker count so
    NO_PARALLEL=1 produces exactly one worker.
  7. Keep the existing worker cap, filtering, max-failure handling, cached-build
    fallback, and interrupt cleanup behavior.
  8. Keep the workflows on macos-latest; do not increase their timeouts or pin
    macOS 15.

This shared fix must cover both unit-test dylibs and example dylibs.

Implementation steps

  1. Add a RED regression to the existing streaming-runner Python tests which
    records when a fake test callback runs and proves it cannot run before the
    fake compile process has completed successfully.
  2. Add a regression proving a failed compilation executes zero collected
    test/example artifacts.
  3. Add a regression proving NO_PARALLEL=1 selects one streaming worker.
  4. Update stream_compile_only() to collect artifacts only.
  5. Update stream_compile_and_run_tests() to submit collected artifacts after
    successful compilation and stabilization.
  6. Replace direct os.cpu_count() use with the repository's
    ci.util.cpu_count.cpu_count() helper.
  7. Update comments/docstrings that currently promise compile/test overlap.
  8. Run the focused Python regression until RED becomes GREEN.
  9. Run:
    • bash test test_streaming_runner_artifact_validation --py
    • bash test --py
    • bash lint
    • bash test --cpp
  10. Open a PR and require both macOS workflows to complete on the current
    macos-latest/macOS 26 image.
  11. Confirm no orphaned runner or example_runner processes remain and the
    workflows finish well below their timeout limits.

Acceptance criteria

  • No test or example callback runs before Meson/Ninja exits successfully.
  • Failed compilation executes no stale, missing, or partially linked
    artifact.
  • --no-parallel/NO_PARALLEL=1 uses exactly one streaming worker.
  • Linux and Windows behavior remains green.
  • The macOS unit workflow passes on macos-latest/macOS 26.
  • The macOS example workflow passes on macos-latest/macOS 26.
  • No macOS workflow pin or timeout increase is introduced.
  • Focused regression, full Python tests, lint, and full C++ tests pass.

Activity

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

    @zackees
    MemberAuthor

    Correction after PR #3643 / macOS 26 validation

    PR #3643 fixed two real correctness bugs in the streaming executor: execution can no longer overlap compilation, and --no-parallel now selects one worker. It was merged before its macOS check completed, however, and the macOS 26 run proves that those changes are not sufficient to fix this issue.

    Failed validation: https://github.com/FastLED/FastLED/actions/runs/29383388561/job/87251581047

    Observed sequence in that job:

    • Compilation completed successfully at 176.49 seconds.
    • The execution phase began at 176.50 seconds with exactly one worker.
    • fl_active_strip_data_json.dylib then hung for the full 600-second subprocess timeout.
    • fastled_core.dylib also hung for 600 seconds.
    • GitHub canceled the job at 30m20s, leaving an orphan runner for cleanup.

    This rules out concurrent linking as the sole cause and confirms that NO_PARALLEL is now honored. The remaining failure is inside the debug shared-library runner path itself.

    The strongest current discriminator is sanitizer configuration: the quick/non-sanitized macOS runner path passes, while the debug path builds both the runner and loaded .dylib files with shared ASan/UBSan and hangs on macOS 26. The Apple runner also has an observability gap: unit-test watchdog setup happens after dlopen(), and the Python timeout currently discards captured child output.

    Revised work plan

    1. Preserve runner stdout/stderr when the Python subprocess timeout fires.
    2. Add unbuffered Apple-runner phase markers around process startup, crash-handler setup, dlopen(), symbol lookup, test invocation, and teardown.
    3. Install a bounded watchdog before crash-handler setup and dynamic loading; its loader-phase timeout path must use async-signal-safe output/exit rather than dyld-dependent stack unwinding.
    4. Reduce the outer diagnostic timeout so one hung artifact produces useful evidence without consuming the entire workflow limit.
    5. Use a macOS 26 run to determine whether the process stalls before main(), during sanitizer/crash setup, or in dlopen().
    6. Remove the exact ASan/dynamic-loader incompatibility while keeping sanitizer coverage and macos-latest; do not pin macOS 15 or merely raise workflow timeouts.
    7. Validate both unit-test and example shared-runner paths on macOS 26, with no orphan processes.
    8. Keep this issue open until the fix is merged and both current-master macOS workflows are green.

    PR #3644 contains the already-reviewed bounded DLL-touch wait and its regression coverage; it will carry the follow-up diagnostics/root fix.

  3. moved this from Done to Triage in FastLED Trackeron Jul 15, 2026
  4. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    Diagnostic/containment update pushed in commit 5f0b697868 on PR #3644.

    It implements the first four steps from the revised plan:

    • preserves captured stdout/stderr when the Python child timeout fires;
    • emits unbuffered Apple-runner phase markers from startup through teardown;
    • arms an async-signal-safe watchdog before crash setup and dlopen();
    • bounds macOS runner subprocesses at 90 seconds while retaining 600 seconds elsewhere.

    The watchdog is deliberately built as a separate macOS-only static library with -fno-sanitize=all. Its signal path uses only write(2) and _exit(2), so it can report a timeout even if ASan/dyld loader locks are involved. Both unit and example runners use it.

    The next PR run is the discriminator:

    1. no startup marker means the stall is before main();
    2. crash-handler-setup means crash handler initialization;
    3. dynamic-load means dlopen() / sanitizer / dyld;
    4. symbol-lookup means dlsym();
    5. invocation means the loaded test/example body;
    6. teardown means cleanup or process exit.

    Once that run supplies the exact phase, the remaining work is:

    1. reproduce/minimize the phase-specific incompatibility;
    2. remove that incompatibility without pinning macOS 15, raising workflow timeouts, or dropping ASan coverage;
    3. validate both unit and example paths on macos-latest;
    4. merge the fix;
    5. validate both workflows again on current master;
    6. close this issue only after those current-master runs are green and leave no orphan runner processes.

    Local validation for this update: focused regression 12 passed; Python CI tests excluding the unrelated long-running local QEMU integration 508 passed / 40 skipped; Ruff checks passed; C++ lint passed; C++ tests 350/350 passed; Python, C++, and Meson review passes clean.

  5. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    The diagnostic run now gives a decisive result: https://github.com/FastLED/FastLED/actions/runs/29385930873/job/87259086238

    • compilation completed and 267 artifacts were collected;
    • ten runners each hit the new 90-second outer timeout;
    • none emitted even the first async-signal-safe startup marker;
    • therefore the macOS 26 stall occurs before main(), during sanitizer/runtime initialization—not in FastLED's dlopen() call or test body.

    This matches the Apple-reported macOS SDK 15+ ASan/dynamically-loaded-debug-library regression (Feedback FB16513866): https://developer.apple.com/forums/thread/774632

    The permanent workaround is pushed in 06cdc873fb. On Apple debug builds only, every runner and dynamically loaded library is compiled with:

    -mllvm -asan-globals=0
    

    ASan heap/stack instrumentation, UBSan, debug symbols, and macos-latest remain enabled. The workaround disables only the affected ASan global-variable instrumentation pass on macOS; Linux and Windows sanitizer configurations are unchanged.

    Local validation after the change: forced Meson reconfiguration and C++ rebuild succeeded, all 350/350 C++ tests passed, C++ lint passed, and the Meson review was clean. The new macOS 26 run is now the acceptance test. If it passes, the remaining required steps are the example-path validation, merge, and current-master unit/example validation before closing this issue.

  6. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    Root-cause refinement: the -asan-globals=0 experiment did not restore the macOS completion time and has been removed from the final diff.

    The exact matching upstream report is LLVM #200447: llvm/llvm-project#200447

    It reproduces with a trivial ASan executable on macOS 26.4 and identifies the pre-main() deadlock as recursive allocation while the ASan runtime inspects dyld's shared cache. The report also confirms that changing ASan options or using older/newer pre-fix runtimes does not help. Apple shipped the runtime fix in Xcode 26.4+, and a reporter confirmed Xcode 26.5 resolves the repro.

    GitHub's current macos-26 image runs macOS 26.4 with Xcode 26.5 as the default, but FastLED's clang-tool-chain compiler was linking its bundled Clang 19 sanitizer runtime. Commit 573a05d93a now keeps clang-tool-chain for compilation while passing Xcode's clang -print-resource-dir to the linker. Both runners and every loaded dylib therefore use the platform-compatible, fixed Xcode sanitizer runtime.

    This preserves the complete ASan instrumentation (including globals), UBSan, debug symbols, and macos-latest. The superseded compiler workaround was removed. Forced local Meson rebuild: 350/350 tests passed; Meson review: clean. The new macOS 26 run is the acceptance test.

  7. changed the title [-]fix(ci): prevent macOS 26 streaming runner hangs[/-] [+]fix(ci): prevent macOS 26 ASan startup hangs[/+] on Jul 15, 2026
  8. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    Confirmed resolution after the runtime-only experiment:

    The exact failure is LLVM #200447 (llvm/llvm-project#200447), a pre-main() ASan initialization deadlock on macOS 26.4. The diagnostic run compiled and collected all 267 artifacts, then ten runners timed out without emitting the first startup marker: https://github.com/FastLED/FastLED/actions/runs/29385930873/job/87259086238

    The 573a05d93a experiment selected Xcode's sanitizer resource directory only at link time while compiling with clang-tool-chain Clang 19. It failed quickly with undefined symbol: __asan_version_mismatch_check_v8, proving that Clang 19 instrumentation cannot be mixed with Xcode's Clang 21 runtime: https://github.com/FastLED/FastLED/actions/runs/29387594533/job/87264018034

    The corrected implementation is commit fe0e73e292 on PR #3644: #3644

    Required implementation, now pushed:

    1. For Apple debug builds, resolve Xcode clang, clang++, and ar through xcrun.
    2. Use that same Xcode toolchain for compiler detection, Meson's native compiler entries, and the setup environment so every sanitized object and dylib has one ASan ABI.
    3. Use Xcode clang's native ld64 path and Darwin's default shared ASan runtime; keep ASan (including globals), UBSan, and debug symbols enabled.
    4. Disable clang-tool-chain-libdeploy only on Apple debug, because it can copy the old bundled compiler-rt next to an Xcode-linked runner.
    5. Always query the selected Xcode compiler version on Apple debug so a stale Clang 19 marker triggers cleanup instead of preserving incompatible objects.
    6. Keep Apple quick/release builds on clang-tool-chain/LLD, and leave Linux/Windows unchanged.
    7. Keep the bounded watchdog, phase markers, retained timeout output, and 90-second macOS containment so future startup regressions fail diagnostically instead of reaching workflow cancellation.

    Regression coverage now proves Xcode tool resolution/failure handling, stale-marker migration, CC/CXX/AR selection, Apple non-debug scoping, and Apple debug-only runtime-deployer suppression.

    Local validation:

    • focused regressions: 20 passed;
    • Python CI tests excluding unrelated local QEMU integration: 517 passed, 39 skipped, 5 subtests passed;
    • clean forced C++ rebuild and execution: 350/350 passed;
    • Ruff checks: passed;
    • final Python and Meson reviews: clean.

    Remaining acceptance steps:

    1. Require the PR's unit tests macos job on current macos-latest to compile and run successfully.
    2. Merge only after the PR checks are green.
    3. On the resulting master, require both unit tests macos and example tests macos to pass on macos-latest.
    4. Confirm the runs finish without orphan runner/example_runner processes.
    5. Close this issue only after both current-master validations are green.

    No macOS pin, workflow timeout increase, or sanitizer-coverage reduction is part of the resolution.

  9. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    Acceptance-run follow-up: the first matched-toolchain job failed during Meson's compiler sanity check, not in ASan and not by cancellation: https://github.com/FastLED/FastLED/actions/runs/29388323772/job/87266129472

    xcrun --find clang++ correctly selected Xcode 26.5 / Apple Clang 21, but directly invoking that binary did not select a macOS SDK. The sanity link therefore failed with ld: library 'c++' not found.

    Commit e6a85aa254 adds the missing Xcode SDK integration:

    1. Resolve the active SDK with xcrun --sdk macosx --show-sdk-path.
    2. Add -isysroot <SDK> to Apple-debug C/C++ compile and link built-in options in the Meson native file.
    3. Set SDKROOT for Meson setup/compiler probes.
    4. Pass Meson's native cpp_args into both manual PCH compiler commands, which otherwise bypass normal target options.
    5. Add regression coverage for SDK resolution, compile/link sysroot emission, setup environment, and both PCH command sites.

    Local validation after this correction: focused regressions 22 passed plus 2 subtests; full Python 519 passed / 39 skipped / 7 subtests; forced C++ reconfiguration/build/execution 350/350; Python and Meson reviews clean.

    The replacement macOS job is now the acceptance run. The issue remains open and no merge will occur until it is green.

  10. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    Post-merge validation found one remaining macOS-only gap, now addressed by PR #3645.

    Current evidence:

    Root cause:
    PR #3644 corrected the sanitizer environment in ci/meson/runner.py, but ci/util/meson_example_runner.py had a separate copied prepare_sanitizer_environment call. That duplicated path continued to inject detect_leaks=1, so unit tests passed while examples failed.

    Resolution in #3645:

    1. Move sanitizer environment preparation into ci/meson/sanitizer_env.py.
    2. Route both unit and example debug runners through the shared helper.
    3. On Darwin only, remove any detect_leaks setting and force detect_leaks=0; ASan and UBSan remain enabled.
    4. Keep non-Darwin LSan suppression behavior unchanged.
    5. Add regression coverage that verifies the Darwin option correction and ensures both runners use the shared helper.

    Local verification:

    • focused regression: 12 passed, 4 subtests passed
    • full Python suite excluding the hardware QEMU test: 521 passed, 39 skipped, 9 subtests passed
    • repository lint: passed
    • focused Python review: clean

    Acceptance remains unchanged: keep this issue open until #3645 is merged and both the macOS unit and macOS example workflows are green on current master. No ESP32/board build is part of this fix.

  11. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    Resolved and validated on current master at merge commit 862508e.

    Final acceptance evidence:

    Shipped fixes:

    Both required macOS workflows are green on the merged revision, so the investigation and fix are complete.

  12. moved this from Triage to Done in FastLED Trackeron Jul 15, 2026
  13. added a commit that references this issue on Jul 15, 2026
    77b97b0
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