Project

General

Profile

Actions

Bug #76335

closed
SZ SZ

DaemonServer destructor does not clean up some initialized objects

Bug #76335: DaemonServer destructor does not clean up some initialized objects

Added by Steven Zuraski 7 months ago. Updated 3 months ago.

Status:
Resolved
Priority:
Normal
Category:
ceph-mgr
Target version:
-
Due date:
% Done:

0%

Source:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Tags (freeform):
Fixed In:
v21.3.0-3401-g0baa598da4
Released In:
Upkeep Timestamp:
2026-09-17T19:18:18+00:00

Description

Found during Unit Testing of DaemonServer within the mgr, a race condition during DaemonServer destruction could produce "pure virtual method called" errors and assertion failures when the timer thread remained active during object destruction:

/home/szuraski/ceph/src/common/Timer.cc: 51: FAILED ceph_assert(thread == __null)

Stack trace:
4: (CommonSafeTimer<...>::~CommonSafeTimer()+0x49)
5: (DaemonServer::~DaemonServer()+0x9e)
6: (SegfaultReproductionTest_DaemonServerTimerRaceCondition_Test::TestBody()+0x197)

Findings:

DaemonServer contains a Timer member with a background service thread for daemon health checks. The destructor was destroying the Timer without properly shutting it down first, causing the Timer thread to still be running when the Timer destructor asserted that the thread should be null. Additionally, if timer callbacks fire after the DaemonServer object begins destruction, they can invoke virtual methods on a partially-destroyed object, resulting in "pure virtual method called" errors.

The destructor was also missing cleanup for the admin socket hook (asok_hook) and messenger (msgr), which are allocated during DaemonServer::init() but were never being properly cleaned up. This could lead to resource leaks and potential crashes if these resources tried to access the destroyed DaemonServer.

Proposed solution: Shutdown the timer thread, admin socket, and messenger before destroying DaemonServer:

DaemonServer::~DaemonServer() {
// Shutdown the timer thread before destroying the object
// to prevent "pure virtual method called" errors {
std::lock_guard l(lock);
if (tick_event) {
timer.cancel_event(tick_event);
tick_event = nullptr;
}
timer.shutdown();
}

// Unregister admin socket commands if they were registered
if (asok_hook) {
AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
admin_socket->unregister_commands(asok_hook);
delete asok_hook;
asok_hook = nullptr;
}
// Shutdown messenger if it was initialized
if (msgr) {
msgr->shutdown();
msgr->wait();
delete msgr;
}
g_conf().remove_observer(this);
}

These bugs can affect MGR daemon shutdown and failover scenarios.


Related issues 1 (1 open — 0 closed)

Related to mgr - Feature #76261: Continued ceph-mgr Unit Test coverage: ActivePyModulesNewSteven Zuraski

Actions

SZ Updated by Steven Zuraski 7 months ago Actions #1

  • Related to Feature #76261: Continued ceph-mgr Unit Test coverage: ActivePyModules added

NM Updated by Nitzan Mordechai 6 months ago Actions #2

  • Assignee set to Steven Zuraski

SZ Updated by Steven Zuraski 3 months ago Actions #3

  • Pull request ID set to 71234

SZ Updated by Steven Zuraski 3 months ago Actions #4

  • Status changed from New to Resolved

UB Updated by Upkeep Bot 3 months ago Actions #5

  • Merge Commit set to 0baa598da42fe1799cbb0f9ce4bb241299225d9d
  • Fixed In set to v21.3.0-3401-g0baa598da4
  • Upkeep Timestamp set to 2026-09-17T19:18:18+00:00
Actions

Also available in: PDF Atom