mlx icon indicating copy to clipboard operation
mlx copied to clipboard

[BUG] JACCL MeshImpl::recv spins forever on peer loss — silent hang, no timeout (UC)

Open Sofille65 opened this issue 4 months ago • 3 comments

Describe the bug

When a peer of an established JACCL mesh becomes unreachable mid-operation (e.g. a Thunderbolt link drops), jaccl::MeshImpl::recv never returns: it polls the dead QP forever. Because the transport is UC with no timeout and no liveness check, the collective never completes, mx.eval blocks forever on Event::wait, and the whole distributed job hangs with zero errno, zero exception, zero log output. Processes stay alive; SIGTERM is never acted on (the interpreter is blocked inside native code), so the only way out is SIGKILL — which on macOS leaves the Metal/RDMA wired pages kernel-held until a reboot.

This is distinct from the connect-time failures (#3467, #3755): init succeeded, traffic was flowing, and the hang appears only when a peer goes away under an established QP.

Native stack of a hung rank (captured live with sample, mlx 0.32.0)

Main thread (why SIGTERM is never delivered):

_PyEval_EvalFrameDefault
  mlx::core::eval(std::vector<mlx::core::array>)
    mlx::core::array::wait()
      mlx::core::Event::wait()
        -[IOSurfaceSharedEvent waitUntilSignaledValue:timeoutMS:]

StreamThread (the actual spin — 1156/1304 samples inside MeshImpl::recv):

mlx::core::scheduler::StreamThread::thread_fn()
  jaccl::MeshImpl::recv(char*, long long, int)          libjaccl.dylib
    tbt_poll_cq                                          libthunderboltrdma.dylib
      tbt_poll_qp_recv → ring_indicies_err               (error path polled in a loop)
      tbt_poll_qp_recv → ring_get_completions_to_check
      tbt_poll_qp_send → ring_indicies_err

Note the driver's poll path is repeatedly hitting ring_indicies_err — the information that the QP is in trouble appears to be visible at the driver level, but MeshImpl::recv keeps polling regardless.

To Reproduce (deterministic)

  • 2+ Macs, TB5 mesh, backend="jaccl" (MeshGroup), any workload doing point-to-point send/recv or collectives in a loop (pipeline-parallel inference is a natural one).
  • Mid-operation, unplug the TB cable between two nodes.
  • All ranks freeze silently. Re-plugging the cable ~1 min later did not unblock the in-flight operation in our test (the QP appears dead for good; only re-init recovers).

Additional occurrence (trigger not captured)

We also observed what appears to be the same signature after ~75 h of continuous serving with no physical action. That trigger was not captured and may have a different root cause; reporting it only as context for how this class of hang shows up in long-running deployments.

Expected behavior

Either of:

  • recv/collectives fail with an error when the peer/link is gone (the driver seems to know — see ring_indicies_err above), or
  • an optional bounded-poll / timeout knob (env var) so integrators can turn a silent hang into a catchable failure.

Today the only robust integration is an application-level no-progress watchdog that SIGKILLs the ranks and reboots the leaked nodes, which is heavy.

Desktop

  • 4× Mac Studio M3 Ultra (Mac15,14), macOS 26.4.1 and 26.5 (mixed across nodes)
  • mlx 0.32.0 (pip), python 3.11
  • TB5 full mesh, RDMA enabled; init is clean (this is not the #3467 GID-selection issue — we work around that one with static link-local IPv4 per TB port, see #3467)

Sofille65 avatar Jul 24 '26 13:07 Sofille65

Related https://github.com/ml-explore/mlx/issues/3862, seems to be a different bug though.

zcbenz avatar Aug 10 '26 07:08 zcbenz

Reproduced this on two M4 Pro Mac minis (macOS 26.5.1) direct-attached over Thunderbolt 5, and instrumented the poll loop to find out what the verbs layer actually reports when a peer goes away. Short version: it reports nothing, so neither of the error-checking approaches under discussion can detect it.

The hang. Two ranks in a tight all_sum loop, then SIGKILL on rank 1. The survivor stops making progress and never returns:

%CPU 100.0  STAT RN          <- spinning, not blocked
main -> jaccl::MeshImpl::all_reduce<float, SumOp<float>> -> tbt_poll_cq
        1927 of 2009 samples

Iteration counter frozen, no error, no log line, no exception. Same signature as the report above.

What ibv_poll_cq returns. I counted every return value in the loop. After the peer died, over 2.6 billion polls:

neg=0   zero=2,636,992,719   pos=3,007,281 (frozen at the pre-kill count)
bad_status=0   errno=0

So the verbs layer never returns an error, and no work completion ever arrives carrying a bad status. The failure mode is silence.

What that rules out. Two fixes have been discussed for this class of bug:

  • checking a negative ibv_poll_cq return — never happens here (neg=0)
  • checking wc.status on completions, as #3152 does — cannot fire here, because pos is frozen and no completions arrive to inspect

#3152 is still worth having for what it targets, completions that arrive carrying an error status. It just is not reachable on this path.

That leaves a deadline or liveness check as the only thing that can turn this into a catchable failure, which is what @Sofille65 asked for in the original report.

One thing that does not reproduce it: bringing the interface down (ifconfig <if> down) changes nothing. Thunderbolt RDMA sits below the IP interface, so the link has to actually go away.

One difference from the report worth flagging. Physically unplugging the cable did not hang on my hardware, it crashed both ranks. Filed separately as #4192. So on M4 Pro / macOS 26.5.1 the trigger that reproduces the silent hang above is peer process death rather than link loss.

Caveats: two nodes rather than four, M4 Pro rather than M3 Ultra, and the counter instrumentation was a local patch that is not proposed for merge.

erwinzhang7 avatar Aug 11 '26 23:08 erwinzhang7

I'm merging this to #4278.

zcbenz avatar Nov 03 '26 03:11 zcbenz