Skip to content

DAOS-19995 cart: hold a group reference for the RPC lifetime - #19526

Open
potatogim wants to merge 4 commits into
daos-stack:masterfrom
potatogim:fix/daos-19955-drain-races
Open

potatogim wants to merge 4 commits into
daos-stack:masterfrom
potatogim:fix/daos-19955-drain-races

Conversation

@potatogim

@potatogim potatogim commented Nov 13, 2026 •

Copy link
Copy Markdown

Fixes DAOS-19995

Reopening with the scope narrowed to the CaRT group reference piece per the review discussion. The drain reordering work from the original branch moved to #19542, and the follow-up ticket DAOS-19995 now tracks the group reference defect separately, as noted when I closed this.

crt_corpc_req_create() and the other sites assigning crp_grp_priv take a group reference when the field is set, so it pairs with the decref in crt_rpc_priv_free(). Without that, an RPC can outlive the group it points at: the uri and address lookups on send and the completion path dereference the group after its last external reference is gone.

This comes with a test case as promised: a new cart functional test, no_pmix_grp_lifetime, runs two crt_launch instances on one node through the grp_lifetime avocado test, following the corpc_errors pattern. Rank 0 creates a secondary group, creates an RPC on it, then destroys the secondary group to drop the last external reference before sending, so the send lookups, the completion, and crt_rpc_priv_free() all run after the group lifetime would otherwise end.

Locally, with the fix reverted the test under valgrind reports invalid reads in crt_grp_priv_get_primary_rank from crt_req_send on a block freed by crt_group_secondary_destroy, and exits 139. With the fix in place the same test completes and valgrind reports no invalid accesses.

The CaRT changes here are the same sixteen lines from the earlier revision that frostedcmos already reviewed.

Steps for the author:

  • Commit message follows the guidelines.
  • Appropriate Features or Test-tag pragmas were used.
  • Appropriate Functional Test Stages were run.
  • At least two positive code reviews including at least one code owner from each category referenced in the PR.
  • Testing is complete. If necessary, forced-landing label added and a reason added in a comment.

After all prior steps are complete:

  • Gatekeeper requested (daos-gatekeeper added as a reviewer).

@potatogim
potatogim requested review from a team as code owners November 13, 2026 05:07
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Ticket title is 'RPCs can outlive group detach without holding a group reference'
Status is 'Open'
https://daosio.atlassian.net/browse/DAOS-19995

@potatogim
potatogim force-pushed the fix/daos-19955-drain-races branch from 5107e6b to e01ec68 Compare November 13, 2026 05:45
@potatogim potatogim changed the title DAOS-19955 client: drain in-flight tasks before destroying the context at teardown DAOS-19955 client: drain tasks before context destroy Nov 13, 2026
@potatogim
potatogim force-pushed the fix/daos-19955-drain-races branch 2 times, most recently from bf79fee to 97a8bd4 Compare November 14, 2026 09:10
@potatogim
potatogim requested review from a team as code owners November 14, 2026 09:10
@potatogim
potatogim force-pushed the fix/daos-19955-drain-races branch 2 times, most recently from b039af7 to d341064 Compare November 14, 2026 10:42
@potatogim

potatogim commented Nov 14, 2026 •

Copy link
Copy Markdown
Author

This branch picked up more work since it was first posted. The drain reordering itself held up, but further runs of the same reproducer (init, four worker threads issuing synchronous ev==NULL array/dfs I/O with injected errors, teardown without joining the workers, 50 cycles) kept surfacing races in the drain paths. Each fix below is grounded in a reproduced trace; in brief:

  • Synchronous workers kept admitting new tasks (and retrying failed ones) into the cancelling scheduler while the drain ran, so the drain spun and the scheduler refcount underflowed. Scheduling into a cancelling scheduler now registers the task and force-completes it under the lock, mirroring tse_sched_complete_inflight() on the claim path; tse_task_reinit() already rejected this case.
  • A task whose daos_event_launch() failed inside dc_task_schedule() was completed without ever being scheduled, and the cancelling branch dropped a scheduler reference it never owned, underflowing the count. A task that is not on a scheduler list no longer drops that reference.
  • The cancelling branch of tse_task_complete() unlinked tasks without running their completion callbacks, and dropped dependency links without freeing a dependent that reached its final reference. Both now follow the same protocol as tse_task_post_process().
  • The drain could complete a task between the moment process_init() published it on the running list and the moment its body ran; the body now runs holding a task reference taken under the lock, with the cancellation result also set under the lock.
  • A late RPC completion callback arrives as a raw task pointer, so a task-based RPC now pins the task for its own lifetime and the finalizer holds a scheduler reference across the drain, keeping dsp_lock valid for that callback.

With these on top, the reproducer completes consecutive 50-cycle runs cleanly, where the first posted revision still aborted within tens of cycles. Happy to split anything out if that is easier to review.

@potatogim
potatogim changed the base branch from release/2.6 to master November 16, 2026 08:37
@potatogim
potatogim requested review from a team as code owners November 16, 2026 08:37
@potatogim
potatogim force-pushed the fix/daos-19955-drain-races branch from d341064 to 13fd77e Compare November 16, 2026 08:40
@daltonbohning
daltonbohning requested review from a team and removed request for a team November 16, 2026 16:11
@potatogim

potatogim commented Nov 17, 2026 •

Copy link
Copy Markdown
Author

The broadened drain-race work moved to #19542, and the scope here is narrowed back to the CaRT group reference piece, tracked in DAOS-19995.

Following the review on DAOS-19955, I understand the overlap this PR tried to harden against as outside the API: once dfs_disconnect() and dfs_release() return, workers still inside dfs_read/dfs_write are operating on freed objects, and no reordering of the scheduler internals can make that safe. A no-overlap variant of the reproducer, with the workers joined before teardown, also completed two 500-cycle runs against a master build with #19542 without a crash, hang, or assert, so I have not found a crash with no DAOS call in flight across teardown.

Rather than opening a new pull request, I reopened this one with the CaRT group reference piece, crt_corpc_req_create() taking a group reference when assigning crp_grp_priv so it pairs with the decref in crt_rpc_priv_free(), now with a test case.

@potatogim potatogim closed this Nov 17, 2026
@potatogim potatogim changed the title DAOS-19955 client: drain tasks before context destroy DAOS-19995 cart: hold a group reference for the RPC lifetime Nov 17, 2026
@potatogim potatogim reopened this Nov 17, 2026
@potatogim
potatogim force-pushed the fix/daos-19955-drain-races branch from 13fd77e to ca71e54 Compare November 17, 2026 09:50
@mchaarawi

Copy link
Copy Markdown
Contributor

/run-ci

@daosbuild3

Copy link
Copy Markdown
Collaborator

An RPC stores its group in rpc_priv->crp_grp_priv without taking a
reference, at every site that assigns the field. crt_rpc_priv_free()
releases no group reference either, so the reference the RPC relies on
is the caller's attach reference. Once crt_group_detach() drops that
reference and the count reaches zero, an RPC that is still alive - for
example a request aborted during context teardown whose completion is
processed after the caller has returned - dereferences the freed group
in crt_rpc_priv_free() and in the timeout and completion paths that
read group state.

Take a group reference wherever crp_grp_priv is assigned:
crt_req_create(), crt_req_create_internal() and the collective root
path in crt_corpc_req_create(). Release it in crt_rpc_priv_free().
crt_req_set_endpoint() replaces the group, so release the previous
reference there before taking the new one.

Fixes: DAOS-19995

Signed-off-by: Jihyeon Gim <potatogim@gluesys.com>
Cover the fix that has an RPC hold a reference on its group: rank 0
creates a secondary group, sends an RPC on it, and destroys the
secondary group while the RPC is still in flight, so the completion
and crt_rpc_priv_free() run after the last external reference on the
group is gone. Without the fix this is a use-after-free on
crp_grp_priv.

The test runs two crt_launch instances on one node through the
grp_lifetime avocado test, following the corpc_errors pattern.

Fixes: DAOS-19995

Signed-off-by: Jihyeon Gim <potatogim@gluesys.com>
Format no_pmix_grp_lifetime.c with the repository clang-format
settings, and use the "(C) Copyright <year> <organization>" form in
the two new test files. Add Gluesys to the spelling dictionary so
pylint accepts it in the docstring.

Signed-off-by: Jihyeon Gim <potatogim@gluesys.com>
@potatogim
potatogim force-pushed the fix/daos-19955-drain-races branch from e52317a to ae1ff3c Compare November 18, 2026 17:46
@frostedcmos

Copy link
Copy Markdown
Contributor

Added #19584 to run these changes through CI

Drop the copied host-name comment, use plain keys for the single
hosts and tests variants, and run the test in daily regression
instead of on every PR.

Signed-off-by: Jihyeon Gim <potatogim@gluesys.com>

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

None yet

Development

Successfully merging this pull request may close these issues.

4 participants