From a654c9c01da5bb6f90b1dc7027ceb90ae084ab64 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Fri, 31 Jul 2026 20:24:35 +0200 Subject: [PATCH] MT#65612 RegThread: lifetime hardening If the owner of the `RegThread` (`RegistrationAgentFactory`) was asked to be destructed, make the destroy process of the reg thread more ordered as well. That makes the thread to stop as soon as the app factory begins its own destruction. This will help to avoid a possible way to end up with a stale (or invalid) DI factory ptr. E.g.: `RegThread` keeps on running, while all the plugins are being torn down by that time already. In this case the `RegThread` can simply call `getFactory4Di()` or `di_f->getInstance()` way after the registrar_client is already partially destroyed. Change-Id: I10e38174d3856e19f2696f8d874ea166e0a035a8 --- apps/reg_agent/RegistrationAgent.cpp | 5 ----- apps/reg_agent/RegistrationAgent.h | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/reg_agent/RegistrationAgent.cpp b/apps/reg_agent/RegistrationAgent.cpp index 0130de28..9f3e0c98 100644 --- a/apps/reg_agent/RegistrationAgent.cpp +++ b/apps/reg_agent/RegistrationAgent.cpp @@ -50,11 +50,6 @@ EXPORT_SESSION_FACTORY(RegistrationAgentFactory,MOD_NAME); -RegistrationAgentFactory::RegistrationAgentFactory(const string& _app_name) - : AmSessionFactory(_app_name) -{ -} - int RegistrationAgentFactory::onLoad() { AmConfigReader cfg; diff --git a/apps/reg_agent/RegistrationAgent.h b/apps/reg_agent/RegistrationAgent.h index 6e715d4d..1505e54e 100644 --- a/apps/reg_agent/RegistrationAgent.h +++ b/apps/reg_agent/RegistrationAgent.h @@ -49,7 +49,7 @@ struct RegInfo { class RegThread : public AmThread { vector registrations; - + void create_registration(RegInfo& ri); bool check_registration(const RegInfo& ri); @@ -64,11 +64,22 @@ class RegThread : public AmThread { class RegistrationAgentFactory: public AmSessionFactory { - RegThread dialer; + RegThread dialer; public: - RegistrationAgentFactory(const string& _app_name); - + RegistrationAgentFactory(const string& _app_name) + : AmSessionFactory(_app_name) + { + DBG("Add new reg agent factory.\n"); + } + ~RegistrationAgentFactory() + { + /* makes the thread stop as soon as the app factory begins its destruction */ + DBG("Requested the reg agent thread to stop.\n"); + dialer.stop(); + dialer.join(); + } + int onLoad(); AmSession* onInvite(const AmSipRequest& req, const string& app_name, const map& app_params);