Repository navigation
Description
Problem
In the osx ch3:tcp Jenkins tests (--with-device=ch3), coll/uoplong 11 occasionally fails, usually as a timeout. The test runs with MPIR_CVAR_ODD_EVEN_CLIQUES=1, which splits the single host into two fake nodes (even ranks and odd ranks), so the test exercises both nemesis shm and the tcp netmod.
Reproducer (local Mac)
Setup: main at 8e64756, --with-device=ch3 --disable-fortran, macOS 26.6.2, Apple clang 21, 4-core arm64 VM with 8 GB.
uoplong alone never failed in more than 100 runs, about 0.2 s each. It fails when several copies run at the same time:
MPIR_CVAR_ODD_EVEN_CLIQUES=1 MPIEXEC_TIMEOUT=180 mpiexec -n 11 ./uoplong # 4 of these running concurrently, in loops
| concurrent jobs | runs | failed | median | max |
|---|---|---|---|---|
| 1 | 20 | 0 | 0.21 s | 0.26 s |
| 2 | 40 | 0 | 0.60 s | 1.90 s |
| 4 | 80 | 1 | 1.59 s | 180.88 s (timeout) |
| 6 | 60 | 0 | 4.59 s | 6.23 s |
The 4-job timeout was a real hang, not a slow run. The other three jobs finished all their remaining runs by t=34 s, and the stuck job sat idle on an otherwise quiet machine until MPIEXEC_TIMEOUT killed it at 180 s. Runs that didn't hang show no gradual slowdown.
Code path
uoplong creates a non-commutative user op (MPI_Op_create(myop, 0, ...)), so for every count the reduce goes to MPIR_Reduce_intra_binomial. This is confirmed with MPIR_CVAR_DUMP_COLL_ALGO_COUNTERS: all 22 calls are MPIR_Reduce_intra_binomial. circ_graph and smp need a commutative op, and reduce_scatter_gather needs a builtin op (coll_algorithms.txt, coll_selection.json reduce-intra-auto).
For a non-commutative op the binomial tree is rooted at 0. With 11 ranks and odd/even cliques:
| step (mask) | messages | transport |
|---|---|---|
| 1 | 1→0, 3→2, 5→4, 7→6, 9→8 | tcp (odd → even) |
| 2 | 2→0, 6→4, 10→8 | shm |
| 4 | 4→0 | shm |
| 8 | 8→0 | shm |
All tcp traffic is in step 1: five concurrent blocking sends of up to 2^20 × 24 B ≈ 25 MB each.
Finding: ENOBUFS from writev is treated as a fatal connection error
With --enable-g=dbg, plus tracing around each MPIC_Send/MPIC_Recv in the binomial loop, the 4-job stress produced 2 failures in 80 runs. Both aborted quickly instead of hanging:
Fatal error in internal_Reduce: Process failed, error stack:
internal_Reduce(181): MPI_Reduce(..., count=524288, dtype=USER<contig>, op=0x98000000, 0, MPI_COMM_WORLD) failed
MPIR_Reduce_intra_binomial(154):
MPIC_Send(163):
MPIC_Wait(99):
MPIR_Wait(745):
MPID_nem_tcp_send_queued(106): Communication error with rank 2
MPID_nem_tcp_send_queued(104): writev to socket failed - No buffer space available
(The second failure was the same at count=1048576, with rank 4.) In both jobs the trace shows the odd senders stopped at step-1 send-start and their even receivers at step-1 recv-start, after all shm steps of earlier calls had completed.
On macOS, a non-blocking writev can fail with ENOBUFS when the kernel runs low on network buffers. That happens easily here, with several jobs pushing tens of MB over loopback. It is temporary, but the tcp netmod treats any errno except EAGAIN as a dead connection:
MPL_large_writev(src/mpl/src/sock/mpl_sock.c) retries only onEINTR.MPID_nem_tcp_send_queued(tcp_send.c, around lines 96-109) andtcp_large_writev(tcp_send.c, around line 228) accept onlyEAGAIN. Anything else goes toMPID_nem_tcp_cleanup_on_errorwith**comm_fail.- The connection state machine in
socksm.c(writes at around lines 455, 511 and 705) has the same EAGAIN-only check.
Open question: abort vs. hang
In the dbg runs the error reached MPI_Reduce on the sender and the job aborted (exit 101). The CI symptom, and the one hang reproduced locally (non-dbg build, no trace), is a timeout instead. The working hypothesis is that it's the same ENOBUFS, hitting a path where the failure does not abort the job, for example:
- on the receiving side when the sender's connection is torn down;
- in the
socksm.cconnection setup.
The remaining ranks would then block forever. This is not confirmed yet. More traced stress runs are in progress to capture a hang and see which step it stalls in.
Possible fix direction
Treat ENOBUFS (and possibly ENOMEM) from writev/write on the tcp socket as a temporary condition, like EAGAIN: keep the request queued and retry later. Unlike EAGAIN, ENOBUFS doesn't guarantee a later POLLOUT wakeup, so the retry may need to come from the progress loop rather than from poll alone.
Activity
hzhou-muse commentedon Oct 16, 2026
Follow-up: hang reproduced with tracing
I ran more traced stress rounds: 4 concurrent
uoplongjobs × 20 runs each,--enable-g=dbg,MPIEXEC_TIMEOUT=60. Round 2 reproduced the hang.Three jobs started together at t=0 and all three failed at the same moment, inside call 20 (count=524288, about 12.6 MB per message):
ENOBUFSerror already described,MPID_nem_tcp_send_queued(104): writev to socket failed - No buffer space available, on the step-1 sends 9→8 and 5→4.Last trace event of each rank in the hung job:
mask=1 recv-start peer=1(waiting on tcp from 1)mask=1 send-start peer=0(tcp send to 0, never completes)mask=2 send-start peer=0(shm, waits for 0)mask=4 send-start peer=0(shm, waits for 0)mask=8 send-start peer=0(shm, waits for 0)So the whole job hangs on one step-1 tcp transfer (1→0, about 12.6 MB) that never completes on either side, and nothing reports an error. It happened at the same instant that the two jobs beside it hit
ENOBUFSon the same kind of transfer. That fits a temporary socket buffer shortage where, on this connection, the condition was silently lost instead of being reported as an error, but this is not confirmed. For example, a write could fail or come up short and then never get aPOLLOUTwakeup to retry it.Overall, about 5 of 160 traced runs failed under this load (4
ENOBUFSaborts, 1 hang). Every failure was in a step-1 odd→even tcp send of count ≥ 524288.Next steps:
writevreturn values and errno, send queue state, poll events) on the rank-1 → rank-0 connection.hzhou-muse commentedon Oct 16, 2026
Follow-up: trying an ENOBUFS retry fix — plain retry is unsafe, a 16 KB write cap looks safe
I tried two changes in the ch3 tcp netmod (
tcp_send.c,tcp_impl.h):MPID_nem_tcp_send_queuedandtcp_large_writevtreatENOBUFS(andEWOULDBLOCK) likeEAGAIN: the data stays in the send queue and is retried from the progress loop.tcp_writev()wrapper passes at mostMPID_NEM_TCP_MAX_WRITEV_SIZEbytes per call. The existing short-write handling queues the rest.The
socksm.chandshake writes are unchanged. They already fail on any short write, includingEAGAIN(FIXME-Z1), so mappingENOBUFSthere would do nothing.Fault injection. A debug hook that fails every Nth
writevwithENOBUFS(N = 2, 3, 7) passesuoplong -n 11andsendflood -n 8with odd/even cliques.Stress. Same setup as before: 4 concurrent
uoplong -n 11jobs,MPIR_CVAR_ODD_EVEN_CLIQUES=1,--enable-g=dbg, 560 runs per configuration.Plain retry corrupts the stream
With the 256 KB cap, 3 runs failed on the receiver side:
The receiver finds an EAGER_SEND header in the middle of a multi-MB rendezvous transfer, so the byte stream is out of sync. Every failed job had a process that had retried after
ENOBUFS(matched by pid ranges). The two jobs whose processes retried only once both passed.Likely cause: in BSD-derived kernels,
sendit()drops the error for a partial transfer only forERESTART/EINTR/EWOULDBLOCK. So awritevcan copy part of the data into the socket and still return-1withENOBUFS, losing the byte count, and retrying then sends those bytes twice. This comes from the BSD code, not yet checked against XNU source. If it holds, the current fatal handling ofENOBUFSis partly justified, because the sender really doesn't know how much was sent. It may also explain the original silent hang: a connection with lost or duplicated bytes can leave a receiver waiting for data that never arrives.16 KB cap: retry looks safe
With writes capped at 16 KB, about one mbuf cluster, there were 0 failures in 560 runs even though
ENOBUFShappened about 90 times more often (2292 retries). The likely reason: when a write fits in one cluster,ENOBUFShappens before any data is copied, so retrying is safe. This is inferred from behaviour; it is not yet confirmed in XNU source.Cost: under this load the median run is about 25–30% slower and the minimum went from 0.2 s to 2.4 s. A 25 MB message now takes about 1600
writevcalls, and the extraENOBUFSretries add busy polling. Not yet measured on an unloaded, optimized build.Next steps
sosend/sendit) thatENOBUFSon a write of one cluster or less means nothing was transferred.ENOBUFS(fall back to small writes), so the normal path keeps large writes.