ds4 icon indicating copy to clipboard operation
ds4 copied to clipboard

Metal ssd-streaming: one hung pread() wedged the whole server forever — the pread task pool waits on the done condvar with no timeout

Open nazerim opened this issue 3 weeks ago • 0 comments

Symptom

ds4-server on macOS (M5 Max 128 GB, Metal, --ssd-streaming, main V4.1 Flash GGUF on the internal SSD) froze completely at 2026-11-09 05:40:10, after ~7 h of continuous agentic traffic on one boot: the log froze mid-request (ctx 37.9k, gen=200) and the process sat at CPU 0.0%; the request thread's sample stack runs through speculative verification (ds41_session_verify → ds41_moe_batch → ds4_gpu_stream_expert_pread_tasks), the in-flight request never returned and later requests just queued. Not an error — silence.

Diagnosis

Thread sample: one streaming-pool worker blocked inside pread() on g_model_fd (ds4_gpu_stream_expert_pread_into, ds4_metal.m:13805 at b3f5018), coordinator waiting for task completion with no timeout (pthread_cond_wait on g_stream_expert_pread_pool_done_cond, ds4_metal.m:14005). The server serves one request at a time: one hung read = total service loss.

Exonerated: system sleep / thermal / jetsam (no events; kernel log clean); the disk itself as a failing device in general (a ls of the volume was instant and a different GGUF on the same volume read fine — the hung read was the main GGUF specifically); the read loop logic (this is a plain pread() that simply never returns).

The escalation is the worst part: SIGKILL did not reap it: the process sat forever in ?Es ("trying to exit", thread stuck in kernel) and never died, and a dd of the same file from a fresh process on a fresh fd hung too. That is consistent with a vnode- or driver-level wedge — unrecoverable from userspace; recovery required a system reboot.

Why this is worth hardening even without a deterministic repro

First occurrence of this signature in ~2 weeks of near-daily 10 h sessions (to 320k context) on this box. But the pool has zero tolerance for this failure class: ds4_gpu_stream_expert_pread_tasks waits for all workers indefinitely and the kernel I/O path offers no cancellation point — so a single hung read converts into a forever-silent stall: the operator sees a frozen engine with no signal anywhere.

Related prior work (both PRs):

  • #238 (May, PR closed unmerged as "fixed more organically") reported a worker stall in a GPU/Metal kernel call — same "stuck worker stops the server" shape, but that process was SIGKILL-able and the layer was GPU, not file I/O.
  • #1125 (open PR) hardens the paths where pread() returns an error (slot return, etc) — a pread that never returns can never take an error path.

Proposal

A bounded completion wait: the coordinator waits the done condvar with a deadline (say 30–60 s, env-tunable). On expiry, mark outstanding tasks failed (the slot-return machinery from #1125 covers these error paths once landed), treat the wedged task's destination buffer as leaked (a late-returning pread() would still write into it), return an error to the in-flight request, and print one line naming the wedged (offset, len). Deliberately not a watchdog thread (cf. #238): no new thread, no process restart — just a deadline on the existing pool wait (the pooled path; the single-task inline path has no wait to bound). It cannot resurrect a driver-level-stuck thread (our instance showed even SIGKILL failing there) — but it turns a silent unbounded hang into a visible bounded failure, and in the milder case (device hiccup that recovers) the server survives.

Happy to send a small PR (deadline + error path + one log line) if wanted.

Environment: macOS 26.7.2 (Darwin 25) arm64, M5 Max, Metal backend, --ssd-streaming. Our build is a fork — but ds4_gpu_stream_expert_pread_tasks, ds4_gpu_stream_expert_pread_into and the pool-wait function holding the 14005 condvar are all byte-identical to upstream b3f5018 (verified by diff), so the seam is upstream code as-is. The spindump capture was lost in the reboot's tmp cleanup; the description above is everything we recorded at the time.

nazerim avatar Nov 09 '26 12:11 nazerim