8000 HardwareDetector deadlocks on any Mac with a display (system_profiler/ioreg pipe not drained before waitUntilExit) · Issue #2 · darkbloomdev/darkbloom · GitHub
[go: up one dir, main page]

Skip to content

HardwareDetector deadlocks on any Mac with a display (system_profiler/ioreg pipe not drained before waitUntilExit) #2

Closed

Description

@agustif

Bug report: darkbloom CLI deadlocks on any Mac with a display (HardwareDetector pipe deadlock)

Version: darkbloom 0.8.10 (macos-arm64, mlx-swift), bundle from /v1/releases/latest
Hardware: Apple M3 Max, 128 GB, macOS 26.6 (build hangs on any Mac with an attached display)
Severity: Critical — every command that loads the runtime snapshot hangs forever. On a laptop/desktop the provider cannot login, start, doctor, status, verify, or models …. It cannot earn.

Symptom

darkbloom <cmd> hangs with no output and no CPU. Affected: login, start, status,
doctor, verify, models catalog, models list (everything that calls
loadRuntimeSnapshot → HardwareDetector.detect()).
Unaffected: --version, --help, local (they don't detect hardware).

Root cause

HardwareDetector shells out to system_profiler / ioreg using Process with an
NSPipe on stdout, and calls Process.waitUntilExit() before draining the pipe.

macOS pipe buffers start at 512 bytes (verified: fcntl(F_SETFL,O_NONBLOCK) +
1-byte writes block after 512). The child fills the buffer, blocks in write(), and never
exits; the parent blocks in waitUntilExit() waiting for a child that is waiting for the
parent to read. Classic pipe deadlock.

This does not reproduce on headless Macs (Mac mini fleet with no display): with no
attached display, system_profiler SPDisplaysDataType output stays under 512 bytes and the
write never blocks. That is almost certainly why it passed testing but breaks in the field
on any machine with a screen.

Measured on the affected machine: system_profiler SPDisplaysDataType -json emits 1260
bytes
(one built-in Liquid Retina XDR panel already exceeds 512).

Confirmed deadlock sites (from disassembly of the shipped binary)

All three follow the same launch → wait → read anti-pattern:

  1. ProviderCore.detectGPUInfo() — system_profiler SPDisplaysDataType -json
    launchAndReturnError: → waitUntilExit (0x101827160) → fileHandleForReading →
    readDataToEndOfFile (0x101827220). Read happens after the wait.

  2. HardwareDetector.detect() (second call) — system_profiler -xml -micro
    (observed as a live blocked child once site 1 was worked around).

  3. ProviderCore.macHardwareSerialNumber() — ioreg -c IOPlatformExpertDevice -d 2
    waitUntilExit (0x101800f08) → readDataToEndOfFile (0x101800f20). Returns
    String?. This one gates attestation identity, so any "kill the child to force a
    fallback" workaround corrupts the serial and breaks attestation.

Reproduction (standalone, no darkbloom needed)

// deadlocks: parent waits, never reads; child blocks writing >512B
int p[2]; pipe(p); pid_t c = fork();
if (c==0){ dup2(p[1],1); dup2(p[1],2); close(p[0]);
  execl("/usr/sbin/system_profiler","system_profiler","SPDisplaysDataType","-json",0); }
close(p[1]); alarm(15); int st;
if (waitpid(c,&st,0) < 0) { /* SIGALRM: DEADLOCK */ }   // <-- fires

Draining p[0] to EOF before waitpid → exits cleanly with 1260 bytes.

Fix

Read the pipe to EOF before waiting, at every site:

let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/sbin/system_profiler")
task.arguments = ["SPDisplaysDataType", "-json"]
let out = Pipe()
task.standardOutput = out
task.standardError  = Pipe()
try task.run()

// drain FIRST — this also synchronizes on the child closing stdout
let data = out.fileHandleForReading.readDataToEndOfFile()
task.waitUntilExit()
guard task.terminationStatus == 0 else { /* existing fallback */ }

Equivalent acceptable fixes: set standardOutput to a FileHandle on a temp file (regular
files never block writers) and read after exit; or use readabilityHandler with async
accumulation. In all cases also add a timeout (e.g. kill the task after N seconds) so a
hung helper degrades instead of hanging the provider forever.

Notes for whoever picks this up

  • The degraded fallbacks already exist and are correct (GPU cores → 0 via the nonzero-exit
    path; serial → nil). The bug is purely the read/wait ordering, not the fallbacks.
  • No environment override skips detection (checked all DARKBLOOM_* / EIGEN* vars);
    detect() runs before config is read, so there is no user-side mitigation.
  • Local workarounds are not viable for operators: patching the binary requires re-signing,
    which either gets SIGKILL'd (team-prefixed entitlements can't be ad-hoc signed) or loses
    the SLDQ2GJ6TL.io.darkbloom.provider keychain group that gates the Secure Enclave
    attestation key. This must be fixed upstream and re-released.

Activity

  1. agustif commented on Aug 24, 2026

    @agustif
    Author

    Closing — filed against a stale mirror by mistake. The canonical repo is https://github.com/Layr-Labs/d-inference. Re-filing the fix there.

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0