Skip to content

mgr/DaemonServer: fix race conditions and resource leaks in shutdown() - #71234

Merged
stzuraski898 merged 1 commit into
ceph:mainfrom
stzuraski898:wip-sz-76335-daemonserver-object-cleanup
Sep 17, 2026
Merged

stzuraski898 merged 1 commit into
ceph:mainfrom
stzuraski898:wip-sz-76335-daemonserver-object-cleanup

Conversation

@stzuraski898

Copy link
Copy Markdown
Contributor

Unit testing revealed that DaemonServer::shutdown() had bugs that could cause crashes during MGR daemon shutdown and failover:

  1. The SafeTimer thread was never joined before destruction. With safe_callbacks=true (the default), timer.shutdown() must be called under the DaemonServer lock so that it can join the timer thread cleanly. Inflight timer callbacks could also invoke virtual methods on a partially destroyed object, causing "pure virtual method called" errors.

  2. The admin socket hook registered in init() was never unregistered or freed, leaving the admin socket with a dangling pointer to the destroyed DaemonServer.

  3. msgr was deleted directly without calling shutdown()+wait() first, racing the messenger dispatch thread against object destruction.

Fix shutdown() to: join the timer under the lock; unregister and delete asok_hook; call msgr->shutdown()+wait() before deleting msgr; and clear the handle_authentication_dispatcher pointer in monc after msgr is fully stopped (msgr is monc's auth server, so no new auth requests can arrive on monc once msgr is joined).

Guard both dereferences of handle_authentication_dispatcher in MonClient::handle_auth_request() against nullptr, so that connections arriving in the brief window between MGR deactivation and the next activation are rejected cleanly via handle_auth_failure() rather than crashing.

Fixes: https://tracker.ceph.com/issues/76335

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

Unit testing revealed that DaemonServer::shutdown() had bugs that
could cause crashes during MGR daemon shutdown and failover:

1. The SafeTimer thread was never joined before destruction. With
   safe_callbacks=true (the default), timer.shutdown() must be called
   under the DaemonServer lock so that it can join the timer thread
   cleanly. Inflight timer callbacks could also invoke virtual methods on a
   partially destroyed object, causing "pure virtual method called"
   errors.

2. The admin socket hook registered in init() was never unregistered or
   freed, leaving the admin socket with a dangling pointer to the
   destroyed DaemonServer.

3. msgr was deleted directly without calling shutdown()+wait() first,
   racing the messenger dispatch thread against object destruction.

Fix shutdown() to: join the timer under the lock; unregister and delete
asok_hook; call msgr->shutdown()+wait() before deleting msgr; and clear
the handle_authentication_dispatcher pointer in monc after msgr is fully
stopped (msgr is monc's auth server, so no new auth requests can arrive
on monc once msgr is joined).

Guard both dereferences of handle_authentication_dispatcher in
MonClient::handle_auth_request() against nullptr, so that connections
arriving in the brief window between MGR deactivation and the next
activation are rejected cleanly via handle_auth_failure() rather than
crashing.

Fixes: https://tracker.ceph.com/issues/76335
Signed-off-by: stzuraski898 <[email protected]>
Assisted by: IBM Bob
@stzuraski898
stzuraski898 force-pushed the wip-sz-76335-daemonserver-object-cleanup branch from e142437 to 00c50ec Compare August 21, 2026 22:27

@NitzanMordhai NitzanMordhai left a comment

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.

lgtm

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath3-testing-20260824.233415-main.

@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test api

@NitzanMordhai

Copy link
Copy Markdown
Contributor

@stzuraski898
stzuraski898 merged commit 0baa598 into ceph:main Sep 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants