[BUG] JACCL "Changing queue pair to RTR failed with errno 22" on Apple Thunderbolt RDMA — GID selection regression in #3412
Describe the bug
JACCL distributed init fails on Apple Silicon Macs (M3/M4) connected via Thunderbolt 5 RDMA with [jaccl] Changing queue pair to RTR failed with errno 22 (EINVAL). The runner crashes immediately on ConnectToGroup; the QP cannot transition to Ready-To-Receive state.
Affects every mlx version since the JACCL refactor (#3412, merged 2026-04-15, commit 4400504a) — bug is still present in current main HEAD e8ebdebe.
Root cause
In mlx/distributed/jaccl/lib/jaccl/rdma.cpp, Connection::info() selects the local GID for the QP destination handle. Pre-refactor, the code used query_gid(ctx, 1, 1, &gid) (always GID index 1). The refactor replaced this with a scan-and-filter loop:
ibv_gid gid;
for (int i = 0; i < port_attr.gid_tbl_len; i++) {
ibv_gid tmp;
if (ibv().query_gid(ctx, 1, i, &tmp) == 0) {
if (*(uint64_t*)&tmp.raw[0] == 0 && *(uint16_t*)&tmp.raw[8] == 0 &&
*(uint16_t*)&tmp.raw[10] == 0xffff) {
gid = tmp;
break;
}
}
}
The filter accepts only IPv4-mapped IPv6 GIDs (the ::ffff:x.x.x.x format used by RoCE v2). Apple Thunderbolt RDMA exposes only link-local IPv6 GIDs (fe80::...):
$ ibv_devinfo -d rdma_en3 -v
hca_id: rdma_en3
transport: Thunderbolt (100)
...
GID[0]: fe80::3474:d9ff:fe9d:cc84
GID[1]: fe80::1042:a3d5:410e:95e9
Neither GID matches raw[0..7]==0 && raw[10..11]==0xffff. The loop never assigns gid, leaving it uninitialized. The garbage value is sent to the peer via the side channel, the peer programs its QP with garbage destination GID, and the kernel rejects the local QP's RTR transition with EINVAL.
Reproduction
- 2 Mac Studio (M3 Ultra or M4 Max) connected via Thunderbolt 5
- macOS 26.x, RDMA enabled (
rdma_ctl status→enabled), Thunderbolt Bridge disabled, individualEXO Thunderbolt Nservices per port - Any
mlx.distributed.init(backend="jaccl")over a 2-node mesh - Crash:
ValueError: [jaccl] Changing queue pair to RTR failed with errno 22
Fix
Initialize gid to zero, prefer the IPv4-mapped GID (existing RoCE v2 behavior), and fall back to a non-zero GID — preferring index 1 (the original pre-refactor behavior, which corresponds to the RDMA port's primary link-local GID on Apple TB).
PR follows.
Environment
- macOS 26.4.1 (build 25E253)
- Apple M4 Max, 2 nodes
- Thunderbolt 5 mesh,
rdma_en3 PORT_ACTIVE, no Thunderbolt Bridge - mlx commit
cc3f3e60(rltakashige fork merged from upstreame8ebdebe)
Related
- exo-explore/exo#1847 (jaccl errno 22/60/2 recurring crashes on M3 Ultra)
- exo-explore/exo#1711 (RDMA stops working — workaround was reboot/cable wiggle)
- exo-explore/exo#1973 (errno 96, similar pattern, maintainer suggested heartbeat)
Confirming this on a different setup, with some additional data points that may help scope the fix.
Setup: 4× Mac Studio M3 Ultra (Mac15,14), macOS 26.4.1 and 26.5 (mixed
across nodes), full TB5 mesh, backend="jaccl" (MeshGroup), mlx 0.31.2 and
0.32.0 (the GID selection in rdma.cpp is unchanged between the two — still
reproduces on 0.32.0).
A nuance to the diagnosis: on our machines the TB ports do expose an
IPv4-mapped GID (::ffff:169.254.x.y) most of the time — because macOS
self-assigns an APIPA IPv4 to each TB interface when its DHCP finds no server.
So the selector usually works, which is why this bug can look intermittent
("works for days, then RTR errno 22 after a reboot or re-cabling"). The failure
window is whenever that APIPA is absent or mid-renumbering:
- at boot, before the APIPA lands;
- after any IPv4 config transition on the interface — we measured the APIPA staying absent for minutes (DHCP DISCOVER runs first; the self-assigned fallback is slow);
- after every link re-negotiation the APIPA often comes back as a different address.
Deterministic repro (no cable pulling needed):
# on one node, drop IPv4 on the TB service backing the mesh port:
networksetup -setv4off "<service name for enX>"
# → mx.distributed.init(backend="jaccl") now fails on both ends:
# [jaccl] Changing queue pair to RTR failed with errno 22
# restore:
networksetup -setdhcp "<service name for enX>"
# → eventually recovers (the APIPA lands after minutes), but the address is
# volatile again — same failure windows on the next boot/re-link
networksetup -setmanual "<service>" 169.254.250.5 255.255.255.0
# → fixes immediately AND durably (see workaround below)
A third failure signature from the same root: after IPv4 config transitions
we've also seen the port's GID table end up with a stale/holey layout (the
::ffff: entry at an unexpected index, or an empty slot) — init then fails
with RTR failed with errno 96 on one rank and Recv failed with errno=2 on
the peers, even though a ::ffff: GID is present. Re-applying the IPv4
(setmanual) re-normalizes the table and clears it.
Data point on the #3468 fallback: we built #3468 at v0.31.2 and A/B-tested
it on this mesh. With fe80-only GID tables on both ends of a link, it does fix
the uninitialized-GID EINVAL — but the chosen link-local GID did not route for
us: errno 22 became RTR failed with errno 60 (ETIMEDOUT). So on setups like
ours the fe80 fallback trades an immediate failure for a timeout; the
IPv4-mapped GID appears to be the only one that routes over Apple TB RDMA (at
least here). Sharing as one data point — the all-fe80 setup in the original
report may behave differently.
Workaround that has held in production for us: assign a static
link-local IPv4 per TB mesh port (unique per port, e.g. a dedicated
169.254.250.0/24 block, mask 255.255.255.0):
networksetup -setmanual "<service for enX>" 169.254.250.N 255.255.255.0
The ::ffff: GID is then always present and immutable. Verified: survives
reboots and physical cable unplug/replug (same address returns on re-link,
where DHCP/APIPA would renumber). This removed the errno 22/96 init failures
entirely on our cluster.
Reproduced this on a pair of M4 Pro Mac minis (macOS 26.5.1) wired directly via Thunderbolt 5.
The workaround, if you just want it working: give the Thunderbolt interface an IPv4 address:
sudo ifconfig en3 inet 169.254.10.1 netmask 255.255.0.0 alias # node 0
sudo ifconfig en2 inet 169.254.10.2 netmask 255.255.0.0 alias # node 1
Stock MLX then works, unmodified: a two-rank all_sum returns correct results over the
Thunderbolt link.
Why? Thunderbolt RDMA ports publish only a link-local IPv6 GID:
rdma_en3: link_layer: Thunderbolt gid_tbl_len: 1024
GID[0] = fe80::347c:94ff:fecd:45c4
Connection::info() accepts only IPv4-mapped GIDs, so on Thunderbolt the loop matches
nothing. ibv_gid gid; is declared uninitialized, so whatever was on the stack is written
into src.global_identifier and handed to the queue pair. The failure then shows up much
later and somewhere else, as Changing queue pair to RTR failed with errno 22.
Assigning an IPv4 address makes an IPv4-mapped GID appear at index 1, which is what the existing code has been looking for all along:
GID[0] = fe80::347c:94ff:fecd:45c4
GID[1] = ::ffff:169.254.10.1
I have opened #4191, which makes the no-usable-GID case throw with that remedy in the message instead of continuing with uninitialized memory. It does not change what works; it changes what you see when it does not.
Closing since this is a network configuration problem and https://github.com/ml-explore/mlx/pull/4191 made the error easier to fix.