Skip to content

ch3:tcp: coll/uoplong 11 occasionally hangs in osx Jenkins tests (ENOBUFS from writev treated as fatal) #8029

Open

Description

@hzhou-muse

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 on EINTR.
  • MPID_nem_tcp_send_queued (tcp_send.c, around lines 96-109) and tcp_large_writev (tcp_send.c, around line 228) accept only EAGAIN. Anything else goes to MPID_nem_tcp_cleanup_on_error with **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.c connection 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

  1. hzhou-muse commented on Oct 16, 2026

    @hzhou-muse
    ContributorAuthor

    Follow-up: hang reproduced with tracing

    I ran more traced stress rounds: 4 concurrent uoplong jobs × 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):

    • Two jobs aborted after about 1 s with the ENOBUFS error 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.
    • The third job hung until the 60 s timeout, and no rank printed any MPI error.

    Last trace event of each rank in the hung job:

    rank last event (call 20)
    0 mask=1 recv-start peer=1 (waiting on tcp from 1)
    1 mask=1 send-start peer=0 (tcp send to 0, never completes)
    2 recv from 3 done, then mask=2 send-start peer=0 (shm, waits for 0)
    4 mask=4 send-start peer=0 (shm, waits for 0)
    8 mask=8 send-start peer=0 (shm, waits for 0)
    3, 5, 6, 9, 10 already moved on to call 21 and blocked behind their parents
    7 finished all calls

    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 ENOBUFS on 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 a POLLOUT wakeup to retry it.

    Overall, about 5 of 160 traced runs failed under this load (4 ENOBUFS aborts, 1 hang). Every failure was in a step-1 odd→even tcp send of count ≥ 524288.

    Next steps:

    • get stacks of ranks 0 and 1 of a hung job;
    • trace inside the tcp netmod (writev return values and errno, send queue state, poll events) on the rank-1 → rank-0 connection.
  2. hzhou-muse commented on Oct 16, 2026

    @hzhou-muse
    ContributorAuthor

    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):

    1. Retry on ENOBUFS. MPID_nem_tcp_send_queued and tcp_large_writev treat ENOBUFS (and EWOULDBLOCK) like EAGAIN: the data stays in the send queue and is retried from the progress loop.
    2. Cap each writev. A tcp_writev() wrapper passes at most MPID_NEM_TCP_MAX_WRITEV_SIZE bytes per call. The existing short-write handling queues the rest.

    The socksm.c handshake writes are unchanged. They already fail on any short write, including EAGAIN (FIXME-Z1), so mapping ENOBUFS there would do nothing.

    Fault injection. A debug hook that fails every Nth writev with ENOBUFS (N = 2, 3, 7) passes uoplong -n 11 and sendflood -n 8 with odd/even cliques.

    Stress. Same setup as before: 4 concurrent uoplong -n 11 jobs, MPIR_CVAR_ODD_EVEN_CLIQUES=1, --enable-g=dbg, 560 runs per configuration.

    no fix retry + 256 KB cap retry + 16 KB cap
    runs 160 560 560
    hangs 1 0 0
    ENOBUFS aborts 4 0 0
    stream corruption 0 3 0
    real ENOBUFS retries n/a (fatal) 25 in 5 procs 2292 in 19 procs
    median / min run time 1.5 s / 0.2 s 2.1 s / 0.2 s 2.75 s / 2.4 s

    Plain retry corrupts the stream

    With the 256 KB cap, 3 runs failed on the receiver side:

    MPID_nem_tcp_recv_handler(1529):
    MPID_nem_handle_pkt(607):
    MPIDI_CH3_PktHandler_EagerSend(619): failure occurred while posting a receive for message data (MPIDI_CH3_PKT_EAGER_SEND)
    MPIDI_CH3U_Receive_data_unexpected(233): Out of memory (unable to allocate 0 bytes)
    

    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 for ERESTART/EINTR/EWOULDBLOCK. So a writev can copy part of the data into the socket and still return -1 with ENOBUFS, 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 of ENOBUFS is 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 ENOBUFS happened about 90 times more often (2292 retries). The likely reason: when a write fits in one cluster, ENOBUFS happens 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 writev calls, and the extra ENOBUFS retries add busy polling. Not yet measured on an unloaded, optimized build.

    Next steps

    • Confirm in XNU source (sosend/sendit) that ENOBUFS on a write of one cluster or less means nothing was transferred.
    • Measure pt2pt bandwidth with the cap on an optimized build.
    • Consider capping only after a connection has hit ENOBUFS (fall back to small writes), so the normal path keeps large writes.
    • Then open a PR without the debug hooks.
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