Skip to content

UCP/FLUSH: Defer a flush issued during the replay of pending requests - #12411

Open
dmitrygx wants to merge 4 commits into
openucx:masterfrom
dmitrygx:topic/ucx/flush-replay-defer
Open

dmitrygx wants to merge 4 commits into
openucx:masterfrom
dmitrygx:topic/ucx/flush-replay-defer

Conversation

@dmitrygx

Copy link
Copy Markdown
Member

What?

Start a flush or a graceful close issued from a send callback during the
replay of pending requests from the progress queue, after the replay ends.

Why?

The wireup replays the pending requests of an endpoint with
UCP_EP_FLAG_BLOCK_FLUSH set. A send which completes when it is posted (for
example a small eager tag or AM message) calls its callback from the replay. A
flush or close issued there started at once:

  • assertion builds abort on UCP_EP_FLAG_BLOCK_FLUSH in ucp_ep_flush_progress();
  • other builds start the flush before the requests still waiting in the
    replay, which were issued before it, so the flush can complete before them.

How?

ucp_ep_flush_lanes_internal() schedules the flush on the progress queue when
the flag is set. By then every replayed request is sent or waits in a pending
queue of a lane, so the flush completes after them.
New test: test_ucp_wireup_1sided.flush_from_replayed_send_cb.

A send posted before the wireup of its endpoint completes waits in the
pending queue of a wireup endpoint. When the lanes are connected,
ucp_wireup_eps_progress() replays the pending requests with
UCP_EP_FLAG_BLOCK_FLUSH set, and a send which completes when it is
posted, such as a small eager tag or AM message, calls its callback
from the replay. A flush or a graceful close issued from that callback
trips the assertion on UCP_EP_FLAG_BLOCK_FLUSH in
ucp_ep_flush_progress(), in any error handling mode, not only with
token failover.

Add test_ucp_wireup_1sided.flush_from_replayed_send_cb: an eager tag
send waits for the wireup, its callback flushes the endpoint, and the
flush must complete with UCS_OK. On transports whose lanes wait for the
wireup, such as rc and ud, it aborts in assertion builds. It is skipped
when the send completes at once.
The wireup replays the pending requests of an endpoint with
UCP_EP_FLAG_BLOCK_FLUSH set: when the lanes are connected, and in token
failover mode from the recovery queue. The replay merges several
pending queues, so a flush must not start until it ends. A request
which completes when it is posted, such as an AM sent short after the
wireup, calls its send callback from the replay. A flush or a graceful
close issued there started at once: assertion builds aborted on the
flag in ucp_ep_flush_progress(), and other builds started the flush
before the requests left in the replay queue, which were issued before
it.

Start such a flush from the progress queue, as the replay does with a
flush request which it finds in the queue. By then each replayed
request is sent or waits in a pending queue of a lane, so the flush
completes after them. The replay order of the sends does not change.

test_ucp_wireup_1sided.flush_from_replayed_send_cb passes now.
@dmitrygx
dmitrygx requested a review from a team as a code owner November 22, 2026 10:32
@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread src/ucp/rma/flush.c Outdated
ucp_request_set_send_callback_param(param, req, send);

if (ucs_unlikely(ep->flags & UCP_EP_FLAG_BLOCK_FLUSH)) {
/* The send callback of a request which the wireup replays issued the

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: the first sentence is hard to parse

Suggested change
/* The send callback of a request which the wireup replays issued the
/* A request which the replay completed inline issued this flush from
* its send callback. The requests which the replay did not send yet
* were issued before the flush, so start it after the replay. */

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/ucp/rma/flush.c Resolved
Comment thread src/ucp/rma/flush.c Resolved
@svc-nvidia-pr-review

Copy link
Copy Markdown

Coverage gap worth noting but not comment-worthy: the test asserts only that the flush completes; it does not verify the ordering guarantee (flush completing after the not-yet-replayed requests were sent). That ordering still relies on the UCT rule that uct_ep_flush() returns UCS_ERR_NO_RESOURCE while the lane's pending queue is non-empty.

@svc-ucx

svc-ucx commented Nov 22, 2026

Copy link
Copy Markdown

🤖 CI Triage Agent — UCX PR (Tests roce on worker 1) · commit 35764592

TL;DR: rcx/test_ucp_fault_tolerance_tf.worker_flush_during_recovery/9 (rc_x / AM|MSG_MEDIUM, token failover mode) failed on this PR; the new "defer flush during replay" path in ucp_ep_flush_lanes_internal() returns an in-progress flush request without ever progressing it while UCP_EP_FLAG_BLOCK_FLUSH is set, so the worker flush issued while a recovery probe is held never completes — exactly the regression this test guards. The deferral must be conditional on the replay actually being in flight and must be re-armed/released when the replay cannot progress.

Full analysis

Summary: gtest job "roce on worker 1" failed with 1 of 9318 tests failing: rcx/test_ucp_fault_tolerance_tf.worker_flush_during_recovery/9, where GetParam() = rc_x/AM|MSG_MEDIUM → make: *** [Makefile:5017: test] Error 1.

Root cause: The only failing test is the dedicated regression test for "idle recovery wireup endpoint blocked worker flush" (test/gtest/ucp/test_ucp_fault_tolerance.cc:1226-1278). It holds an aux recovery probe completion (mock recovery_probe_hold), issues ucp_worker_flush_nb(), and requires it to complete with UCS_OK within 1s (EXPECT_EQ(UCS_OK, flush_status) << "idle recovery wireup endpoint blocked worker flush"); the test even documents that the "regression leaves worker flush incomplete". The PR head commit adds a new early-return in ucp_ep_flush_lanes_internal():

659: if (ucs_unlikely(ep->flags & UCP_EP_FLAG_BLOCK_FLUSH)) {
663:     ucp_trace_req(req, "flush ep %p starts after the replay", ep);
664:     ucs_callbackq_add_oneshot(..., ucp_ep_flush_resume_slow_path_callback, req);
666:     goto out;   /* returns req+1 == INPROGRESS, flush never progressed here */
667: }

A per-EP flush taken from the worker-flush state machine (ucp_worker_flush_progress() → ucp_ep_flush_internal(), flush.c:860) now returns INPROGRESS and bumps comp_count instead of completing, and its only resumption is a one-shot callback whose body (ucp_ep_flush_progress()) asserts !(ep->flags & UCP_EP_FLAG_BLOCK_FLUSH) (flush.c:131) and performs no re-arming if the replay is still blocked. With the recovery wireup EP stuck (probe completion held, pending requests still queued on the wireup EP, ucp_worker_flush_ops_count_add(+1) in ucp_wireup_ep_pending_add(), wireup_ep.c:184), the deferred EP flush never finishes, so the worker flush stays UCS_INPROGRESS past the 1s deadline. Only the token-failover fixture (test_ucp_fault_tolerance_tf, which replays via tokens) hits it — the plain fixture's identical test passed. Note: the Azure API only returns the log tail, so the exact failing EXPECT line is not quoted in the log; the failure summary plus the test's own design make this the mechanism.

Implicated commit: [REDACTED:Hex High Entropy String] — "UCP/FLUSH: Defer a flush issued during the replay of pending requests" (Dmitrii), PR #12411

File: src/ucp/rma/flush.c:659-667 (deferral), with resumption at src/ucp/rma/flush.c:353-363 and 399-427; test at test/gtest/ucp/test_ucp_fault_tolerance.cc:1245-1274

Suggested fix: Narrow the deferral so it cannot stall unrelated flushes and cannot wait forever:

  1. Defer only for a flush genuinely issued from inside the replay (e.g. an explicit "replay in progress on this EP" state / the request being issued from a replayed request's send callback), not for every flush seen while UCP_EP_FLAG_BLOCK_FLUSH happens to be set — in particular skip the deferral for internal worker-flush requests (UCP_REQUEST_FLAG_RELEASED / worker_req != NULL).
  2. Make the resume path self-healing: in ucp_ep_flush_resume_slow_path_callback() re-check UCP_EP_FLAG_BLOCK_FLUSH and re-arm via ucp_ep_flush_request_resched() instead of calling ucp_ep_flush_progress() (which asserts the flag is clear), and explicitly kick the deferred flush when the replay finishes or is abandoned (recovery give-up / lane failure / EP close) so an idle recovery wireup EP cannot pin a worker flush.
  3. Re-run rcx/test_ucp_fault_tolerance_tf.worker_flush_during_recovery/* plus test_ucp_flush_lane_recovery.lane_replaced_during_inprogress_flush locally with assertions enabled before re-pushing.

Related: PR #12411 (this change); PR #11988 "UCP/WIREUP: fix worker flush hang from recovery wireup ep" (the bug this test protects against); PR #12274 "Clear a recovered lane only after its probe succeeds"

🛡️ This comment had 1 potential secret(s) redacted (Hex High Entropy String). See request_id 4de0ce4b-d20e-44cf-b7bc-9a72e33facaa in the triage console for the audit trail.

A flush which a send callback issues during the replay of pending
requests starts from a progress callback after the replay. Signal the
worker when the callback is added, as the failover restart of a flush
does, so an application which arms the worker and waits for events
after this progress call still runs the flush.

Also reword the comment of the deferral, and format the test as the
code style check suggests.
@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread test/gtest/ucp/test_ucp_wireup.cc Resolved
The wireup replays pending requests with UCP_EP_FLAG_BLOCK_FLUSH set,
and a send callback of a replayed request can issue a flush there.
test_ucp_wireup_1sided.flush_from_replayed_send_cb covers it only where
the send waits for the wireup and completes inline in the replay, and it
passes as well when the callback runs outside the replay.

Add test_ucp_flush.blocked_flush_starts_after_replay, which sets the
flag directly: a flush issued then must not start while the flag is
set, and must complete after it is cleared. Without the deferral it
aborts on the assertion in ucp_ep_flush_progress().
@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

@svc-nvidia-pr-review

Copy link
Copy Markdown

test/gtest/ucp/test_ucp_wireup.cc

In flush_from_replayed_send_cb, arg is a stack object passed as user_data, and request_wait() uses ucp_request_release(), which keeps the callback enabled. If the wait ever hits the deadline, the send callback would later write to a dead stack frame and issue an unobserved flush. This only occurs on an already-failing test, so it is not blocking, but the lifetime is fragile.

test/gtest/ucp/test_ucp_flush.cc

blocked_flush_starts_after_replay deterministically covers the new branch (request returned, started_lanes == 0, later completion), but it does not assert the ordering property itself; that still relies on the UCT rule that uct_ep_flush() returns UCS_ERR_NO_RESOURCE while the lane pending queue is non-empty.

test/gtest/ucp/test_ucp_wireup.cc

flush_from_replayed_send_cb only skips when the send completes inline (req == NULL); when a request is returned, the send may complete outside the replay window, so the test can pass without exercising the fixed path. Acceptable as an integration-level smoke test on top of the deterministic flush test.

@svc-ucx

svc-ucx commented Nov 22, 2026

Copy link
Copy Markdown

🤖 CI Triage Agent — UCX PR (Tests new on worker 3) · commit 80fa627f

TL;DR: The gtest run failed with exactly one test — rcx/test_ucp_fault_tolerance_tf.initiator_failure/14 (rc_x/PUT|AM|FLUSH) — the only variant that issues PUT+AM+ucp_ep_flush_nbx on a lane being failed over, i.e. precisely the path this PR's new "defer flush during replay" code touches; the deferred flush is re-armed with a bare one-shot callback that never re-checks UCP_EP_FLAG_BLOCK_FLUSH, so the flush can resume before/while the pending-request replay is still blocking it.

Full analysis

Summary: make test in build-test/test/gtest exited with error 1: 9220/9221 tests passed, rcx/test_ucp_fault_tolerance_tf.initiator_failure/14, where GetParam() = rc_x/PUT|AM|FLUSH FAILED (log line [ FAILED ] at 20:01:11, make: *** [Makefile:5017: test] Error 1).

Root cause: The failing variant is the single TEST_OP_PUT | TEST_OP_AM | TEST_OP_FLUSH variant (test/gtest/ucp/test_ucp_fault_tolerance.cc:66-68), run under UCX_FAILOVER_MODE=token (test_ucp_fault_tolerance_tf, line 952). It runs test_put_am_flush_with_injected_failure(), which invalidates a lane and then submits ucp_put_nbx + ucp_am_send_nbx + ucp_ep_flush_nbx on the same endpoint, asserting all three complete with UCS_OK and that the error callback is never invoked (lines 412-437). This is exactly the flow modified by the branch's only functional change, the new deferral in ucp_ep_flush_lanes_internal():

  • src/ucp/rma/flush.c:659-668 — when UCP_EP_FLAG_BLOCK_FLUSH is set (pending queues being merged during failover replay), the flush is not progressed and is instead re-armed with ucs_callbackq_add_oneshot(..., ucp_ep_flush_resume_slow_path_callback, req) + ucp_worker_signal_internal().
  • ucp_ep_flush_resume_slow_path_callback() (flush.c:353-363) calls ucp_ep_flush_progress() unconditionally, and ucp_ep_flush_progress() begins with ucs_assertv(!(ep->flags & UCP_EP_FLAG_BLOCK_FLUSH), ...) (flush.c:131). Nothing guarantees the replay has finished when the one-shot fires, and unlike the pre-existing ucp_ep_flush_request_resched() (flush.c:399-427) the new path performs none of the state resets/re-checks, and the one-shot is consumed so there is no second deferral. Result: the flush can be started ahead of requests the replay has not re-sent yet (ordering violation on the failed-over lane), which in this test surfaces as a non-UCS_OK PUT/AM/FLUSH status or a spurious error callback.

Note the follow-up commit 77bfc43a ("Wake the worker for a flush deferred by the replay") was already an attempt to patch this same deferral and is included in this build, which still fails — the deferral mechanism itself is the problem, not just the missing wakeup.

Implicated commit: 35764592 "UCP/FLUSH: Defer a flush issued during the replay of pending requests" (author Dmitrii), with follow-up 77bfc43a "UCP/FLUSH: Wake the worker for a flush deferred by the replay" — both on topic/ucx/flush-replay-defer (PR #12411, head 80fa627f).

File: src/ucp/rma/flush.c:659-668 (deferral) and src/ucp/rma/flush.c:353-363 / :131 (resume callback vs. BLOCK_FLUSH assertion); test: test/gtest/ucp/test_ucp_fault_tolerance.cc:382-437

Suggested fix:

  1. Make the deferral self-healing: in ucp_ep_flush_resume_slow_path_callback(), re-check ep->flags & UCP_EP_FLAG_BLOCK_FLUSH and, if still set, call ucp_ep_flush_request_resched(ep, req) (re-arm) instead of ucp_ep_flush_progress(). Equivalently, replace the hand-rolled ucs_callbackq_add_oneshot() in ucp_ep_flush_lanes_internal() with ucp_ep_flush_request_resched() so the existing state-reset/assert logic is reused.
  2. Better: hook the deferred flush into the replay completion point (clear of UCP_EP_FLAG_BLOCK_FLUSH) rather than the generic progress queue, so the flush is guaranteed to start strictly after all replayed requests were (re)submitted.
  3. Reproduce/verify locally with UCX_FAILOVER_MODE=token ./gtest --gtest_filter='rcx/test_ucp_fault_tolerance_tf.initiator_failure/14' --gtest_repeat=50 on an rc_x node. Caveat: the Azure log is truncated to its tail, so the per-assertion message for this test is not in the retrieved text — please re-post the surrounding [ RUN ] rcx/test_ucp_fault_tolerance_tf.initiator_failure/14 block (or attach --gtest_output=xml) to confirm whether it failed on the EXPECT_EQ(UCS_OK, status) at line 422 or the ASSERT_EQ(0, m_total_err_count) at line 437.

Related: PR #12411 (this change); earlier flush/failover work in the same area: #11923 (UCP/FLUSH: topology-safe selective endpoint flush), #12274 (UCP/WIREUP: Clear a recovered lane only after its probe succeeds), #12371 (UCP/FT/AM: token failover support, last touch of this test file).

@dmitrygx

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).

@svc-ucx

svc-ucx commented Nov 23, 2026

Copy link
Copy Markdown

🤖 CI Triage Agent — UCX PR (AddressSanitizer BlueField on worker 0) · commit 80fa627f

TL;DR: The ASAN gtest job failed on LeakSanitizer, not on an assertion: 68 KB in 17 allocations leaked, all rooted in the setup of test_ucp_proto_mock_rcx_speed_change.rma_get (an rc_mlx5 iface, its devx objects, two wireup proxy eps and their QPs were never closed), which points at the new "defer flush during pending replay" path added by this PR leaving the close/discard flow unfinished.

Full analysis

Summary: make test in the AddressSanitizer BlueField job exited with code 1 — SUMMARY: AddressSanitizer: 68024 byte(s) leaked in 17 allocation(s), every leak stack ending in test_ucp_proto_mock_rcx_speed_change_rma_get_Test::init().

Root cause: All leaked allocations belong to the UCP entity created by that one test case:

  • ucp_init → uct_ib_md_open → uct_ib_mlx5_devx_alloc_uar (md UAR, 152 B)
  • ucp_worker_create → ucp_worker_iface_open → mock_iface::iface_open_mock → uct_rc_mlx5_iface_t_new (CQ umem, dbrec page, SRQ umem)
  • ucp_ep_create → ucp_wireup_init_lanes → ucp_wireup_ep_create (2× uct_stub_iface_open, 832 B) and ucp_wireup_ep_connect → uct_rc_mlx5_ep_t_new (ep struct + 64 KB QP buffer)

i.e. one rc_mlx5 interface and one endpoint (plus its wireup proxies) were never closed, while the rest of the UCP context was torn down normally (ucp_test_base::entity::cleanup() → m_workers.clear() did run, otherwise the leak set would be orders of magnitude larger). That is the signature of UCT endpoints/ifaces being orphaned by an unfinished flush/discard, and test_ucp_proto_mock_rcx_speed_change is precisely the test that drives repeated lane reconfiguration (set_port_speed() → new ep/rkey configs → pending-request replay), which is the code path this PR changes.

The new code is ucp_ep_flush_lanes_internal() (src/ucp/rma/flush.c:659-668): when UCP_EP_FLAG_BLOCK_FLUSH is set the flush is not started — it is only parked as a one-shot progress callback (ucp_ep_flush_resume_slow_path_callback) and returned as in-progress. Such a request is on no EP list (not in flush_state->reqs, not in any UCT pending queue), so it is invisible to EP purge/close, and ucp_ep_flush_progress() even asserts !(ep->flags & UCP_EP_FLAG_BLOCK_FLUSH) when the one-shot finally runs (unlike ucp_ep_flush_progress_pending(), which re-checks and reschedules). If the one-shot is dropped or runs after the EP/lane state changed, the flush that was supposed to drive destruction of the replaced/discarded lanes never completes and those UCT eps/ifaces leak exactly as reported.

Implicated commit: 3576459 "UCP/FLUSH: Defer a flush issued during the replay of pending requests" (Dmitrii), with follow-up 77bfc43 "UCP/FLUSH: Wake the worker for a flush deferred by the replay" (both on this PR branch; HEAD 80fa627)

File: src/ucp/rma/flush.c:659-668 (deferred-flush path), interacting with src/ucp/rma/flush.c:131 / :353-363 (resume callback) and test/gtest/ucp/test_ucp_proto_mock.cc:5116 (failing test)

Suggested fix:

  1. Make the deferred flush request reachable from the EP: register it on the EP (e.g. flush_state->reqs / a dedicated deferred list) when taking the UCP_EP_FLAG_BLOCK_FLUSH branch, and fast-forward (ucp_ep_flush_request_ff) + remove its one-shot in ucp_ep_req_purge/EP-close so a close/discard flush can never be lost.
  2. In ucp_ep_flush_resume_slow_path_callback(), re-check UCP_EP_FLAG_BLOCK_FLUSH and reschedule (same logic as ucp_ep_flush_progress_pending(), flush.c:443-446) instead of falling into the assertion in ucp_ep_flush_progress().
  3. To confirm locally: run gtest --gtest_filter='*rcx_speed_change*' under ASAN with UCX_LOG_LEVEL=req and check for a lingering ucp_worker_discard_uct_ep / un-completed flush on the replaced lanes before process exit.

Related: PR #12411 (this change); possibly relevant neighbours: #12404 (SGL replay handles), #12360 "Close endpoints by force on worker destroy", #12274 (lane recovery/probe)

@dmitrygx

dmitrygx commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

Re the triage of Tests new on worker 3: not caused by this PR. The test fails only on the logged error rc_mlx5_ep.c:158 Invalid am_short length: 1034 (expected: <= 236): after the token purge, an AM short sent on a lane with device memory is reposted on a lane without it. The same error fails rcx/test_ucp_fault_tolerance_tf on other PRs since #12371 (#12339, #12281). The deferred flush cannot start during the replay: the replay sets and clears UCP_EP_FLAG_BLOCK_FLUSH without progressing the worker, and this test does not issue a flush from a send callback.

Re the LeakSanitizer triage of the rerun: also not this PR. All tests passed; the leak is from test_ucp_proto_mock_rcx_speed_change init, where ucp_ep_create fails with rc_mlx5 alone and the lanes it already created are not destroyed. It fails the ASAN BlueField job on other PRs since #11901 (e.g. #12410).

@dmitrygx dmitrygx added the WIP-DNM Work in progress / Do not review label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP-DNM Work in progress / Do not review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants