Bug #76335
closedDaemonServer destructor does not clean up some initialized objects
0%
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.
SZ Updated by Steven Zuraski 7 months ago
- Related to Feature #76261: Continued ceph-mgr Unit Test coverage: ActivePyModules added
NM Updated by Nitzan Mordechai 6 months ago
- Assignee set to Steven Zuraski
SZ Updated by Steven Zuraski 3 months ago
- Pull request ID set to 71234
SZ Updated by Steven Zuraski 3 months ago
- Status changed from New to Resolved
UB Updated by Upkeep Bot 3 months ago
- 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