Skip to content

DAOS-19962 client: own scheduler per library generation - #19525

Closed
potatogim wants to merge 2 commits into
daos-stack:masterfrom
potatogim:fix/daos-19962-generation-scheduler
Closed

potatogim wants to merge 2 commits into
daos-stack:masterfrom
potatogim:fix/daos-19962-generation-scheduler

Conversation

@potatogim

@potatogim potatogim commented Nov 13, 2026 •

Copy link
Copy Markdown

Fixes DAOS-19962
Builds on #19526 (DAOS-19955 drain fixes; merge that first)

The global scheduler is a single static object reused across library generations. A worker still inside daos_event_priv_wait() from the previous generation can race the next daos_eq_lib_init() re-initializing the object in place: the memset clears the cancellation flag and invalidates the mutex and refcount state while the stale worker is mid-callback. With the DAOS-19955 drain fixes in place this layer surfaces on its own, as an EBUSY mutex destroy in tse_sched_fini, a destroyed-mutex assertion in tse_sched_priv_decref, or a permanent epoll spin in the private event wait. All three were captured under gdb with the standalone reproducer from DAOS-19955 (teardown racing in-flight operations, then immediate re-initialization).

Each daos_eq_lib_init() now allocates a fresh scheduler object and the previous generation's object is kept allocated, so stale waiters still see a valid, cancelled scheduler and unwind instead of touching memory the new generation owns. Waiters bail out when the library generation changed underneath them or the scheduler was cancelled, submissions racing the final fini are rejected, and thread-private events created under a previous generation are re-initialized.

With both this and the DAOS-19955 layer in place, the reproducer completed 50 teardown/reinit cycles back-to-back in my testing with no abort and no hang, both on a 2.6.5 single-node deployment (where the failures were first reproduced) and on a master single-node deployment; previously every run aborted or hung within tens of cycles. I am also keeping a release/2.6 backport branch ready in my fork, and will request the 2.6/2.8 backports once this lands on master.

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

Copy link
Copy Markdown

Ticket title is 'Client abort or hang when teardown races re-initialization: global scheduler object is reused across library generations'
Status is 'Open'
https://daosio.atlassian.net/browse/DAOS-19962

@potatogim
potatogim force-pushed the fix/daos-19962-generation-scheduler branch from 643380f to 14167c7 Compare November 13, 2026 05:45
@potatogim potatogim changed the title DAOS-19962 client: give each library generation its own scheduler DAOS-19962 client: own scheduler per library generation Nov 13, 2026
@potatogim
potatogim force-pushed the fix/daos-19962-generation-scheduler branch from 14167c7 to 4dbf65a Compare November 13, 2026 05:50
Comment thread src/cart/crt_rpc.c
Comment on lines +577 to +582
/* the RPC can outlive the group view detach (e.g. an
* in-flight request aborted during crt_context_destroy);
* release the reference taken when crp_grp_priv was set */
if (rpc_priv->crp_grp_priv != NULL)
crt_grp_priv_decref(rpc_priv->crp_grp_priv);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Either this decref needs to be bypassed for corpcs, or corpc_create needs to also take a ref when assigning grp_priv:

in crt_corpc.c:

387         crt_rpc_priv_init(rpc_priv, crt_ctx, false /* srv_flag */);
388  << ADD addref here >>
389         rpc_priv->crp_grp_priv = grp_priv;

@potatogim potatogim Nov 14, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@frostedcmos I believe the current head already covers this: crt_corpc_req_create() now takes a group reference when assigning crp_grp_priv, so it pairs with the decref in crt_rpc_priv_free() the same way the regular request path does. This landed in the update I posted after the revision you looked at, so the asymmetry should be gone - thanks for pointing it out, it was easy to miss with the collective path being the less common one.

@potatogim
potatogim force-pushed the fix/daos-19962-generation-scheduler branch 2 times, most recently from 97a8bd4 to 24575a4 Compare November 14, 2026 10:42
@potatogim

potatogim commented Nov 14, 2026 •

Copy link
Copy Markdown
Author

This branch also moved past its first posted revision. Beyond the rebase, the generation machinery changed in two ways, driven by the same reproducer runs that hardened the DAOS-19955 branch:

  • The finalizer now completes the current generation's scheduler (the base branch instead keeps the static scheduler alive), so a late completion path holding a pinned task finds a cancelled but valid scheduler and dsp_lock rather than freed memory.
  • daos_event_priv_wait() now tracks the number of waiters; the finalizer waits for them to leave before destroying the CaRT context, and the wait itself aborts when the scheduler was cancelled or the library generation changed underneath it.

The note from the original description still holds for the updated pair of branches: 50 teardown/reinit cycles complete cleanly, over consecutive runs, where every run previously aborted or hung within tens of cycles.

Destroying the CaRT context at the top of daos_eq_lib_fini() left
in-flight tasks with no way to make progress, so their completion
callbacks re-entered a half-torn-down scheduler during teardown: the
drain lost task references, cancelled tasks were unlinked without
completing, and late bulk completions touched freed shards.

The drain now runs while the context can still make progress, before
the context is destroyed. In-flight task and scheduler references are
tracked across the drain so completion callbacks hold the objects they
re-enter: a task-based RPC holds a task reference for its own lifetime
(the completion callback arrives as a raw pointer, and without the
reference a scheduler cancel could free the task before the late
callback ran and re-entered tse_task_complete() on freed memory). Task
completion ownership is decided before the callbacks run:
tse_task_complete() moves the task into a callbacks-executing state
under the scheduler lock, and the drain skips tasks in that state, so
it can never free callback nodes a concurrent traversal still advances
to; a task claimed by the drain is left entirely to it. Dependency
links unwind the same way tse_task_post_process() does, dropping each
dependent's dependency count under the dependent's own scheduler lock
(kept held for same-scheduler dependents), without completing the
dependent itself - the drain or the completing worker owns that. The
drain loop holds one scheduler reference for its whole duration and
releases it together with the initial reference at the end. A bulk
completion landing after the drain gave up on the transfer is
tolerated.

The drain also exposed two smaller issues: an RPC did not hold a CaRT
group reference for its lifetime (including the collective root path
in crt_corpc_req_create()), and the transaction path dereferenced a
handle after -DER_NO_HDL. Both are addressed here.

Fixes: DAOS-19955

Signed-off-by: Jihyeon Gim <potatogim@potatogim.net>
Give each daos_eq_lib_init() generation its own heap-allocated global
scheduler instead of reusing one static object, so a stale
thread-private event from a previous generation keeps a valid
(cancelled) scheduler.

The finalizer drains in-flight tasks on the global scheduler while the
CaRT context can still make progress, and holds one extra scheduler
reference across the drain so late completion paths - including the
RPC completion callback, which receives the task as a raw pointer and
now pins the task for the RPC lifetime - always find a live scheduler
and dsp_lock.

Also track the waiter count for threads inside
daos_event_priv_wait(): the finalizer waits (bounded) for them to
leave before destroying the context, and the wait itself aborts when
the scheduler is cancelled or the library generation changed.

Fixes: DAOS-19962
Signed-off-by: Jihyeon Gim <potatogim@potatogim.net>
@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 requested a review from a team as a code owner November 16, 2026 08:37
@potatogim
potatogim force-pushed the fix/daos-19962-generation-scheduler branch from 24575a4 to 69936f7 Compare November 16, 2026 08:40
@daltonbohning
daltonbohning removed request for a team November 16, 2026 16:12
@potatogim

Copy link
Copy Markdown
Author

Closing in favor of #19542.

Following the review on DAOS-19962, the layer this PR addressed, the global scheduler object being reused across library generations, is covered by #19542 through the eq_gen counter and the thread-private event reinit, which reads like the more targeted fix. A no-overlap variant of the reproducer, with the workers joined before teardown, completed two 500-cycle runs against a master build with #19542 without a crash, hang, or assert.

The drain-race hardening this PR carried on top of #19526 is being closed by the same review, and the CaRT group reference piece from #19526 will come back as its own PR with a test case.

@potatogim potatogim closed this Nov 17, 2026
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.

2 participants