From 1ec74572da1beaff2c1faf1a9fa03daee625f01d Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Wed, 27 May 2026 15:41:28 +0200 Subject: [PATCH] MT#59962 AmSession: avoid dead-lock in `setStopped()` In case the override func of virtual `onStop()` anyhow reaches the AmSession again, and falls into the scope where the same mutex lock is used (snapshot_lock) this will be a dead-lock. Hence preserve such, but manually managing the lock, and release it, when calling the virtual func. Change-Id: I7c7c4700767dd3aed1c482559be02e3a97cca407 --- core/AmSession.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/AmSession.cpp b/core/AmSession.cpp index ec57e57f..38cc9fc3 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -531,15 +531,20 @@ void AmSession::finalize() } void AmSession::setStopped(bool wakeup) { - /* make snapshot safe */ - lock_guard lock(snapshot_lock); + /* explicit lock management, for the case when onStop()'s override + * anyhow reaches the same mutex lock in similar scope. + */ + snapshot_lock.lock(); if (!sess_stopped.get()) { sess_stopped.set(true); + snapshot_lock.unlock(); /* release now for dead-lock safety */ onStop(); } + snapshot_lock.lock(); if (wakeup) AmSessionContainer::instance()->postEvent(getLocalTag(), new AmEvent(E_TERMINATE_LEG)); + snapshot_lock.unlock(); } string AmSession::getAppParam(const string& param_name) const