From a0daff76aea596d19fb33b36b174a321e98993bd Mon Sep 17 00:00:00 2001 From: Subramanian Date: Mon, 2 Nov 2026 10:07:39 -0500 Subject: [PATCH] RDKEMW-28136: Guard task executors against exceptions Reason for change: None of the three task executors caught exceptions. A throwing task escaped the thread function and called std::terminate, killing the session-server process - and every session in it - with no error log. On the main thread a thrown exception also skipped the state->done signal, hanging any enqueueTaskAndWait waiter before termination. MainThread::mainThreadLoop, WorkerThread::taskHandler and EventThread::threadExecutor now catch std::exception and unknown exceptions, log them, and continue the loop. On the main thread the state->done signal still runs after a failed task so waiters are released. Test Procedure: Enqueue a throwing task on each executor; verify the process survives, the exception is logged, and enqueueTaskAndWait callers are released. Existing unit tests pass. --- common/source/EventThread.cpp | 15 ++++++++++++++- media/server/gstplayer/source/WorkerThread.cpp | 13 ++++++++++++- media/server/main/source/MainThread.cpp | 13 ++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/common/source/EventThread.cpp b/common/source/EventThread.cpp index e46662118..d9c8acaf8 100644 --- a/common/source/EventThread.cpp +++ b/common/source/EventThread.cpp @@ -87,7 +87,20 @@ void EventThread::threadExecutor() m_lock.unlock(); if (func) - func(); + { + try + { + func(); + } + catch (const std::exception &e) + { + RIALTO_COMMON_LOG_ERROR("Exception thrown by event thread callback: %s", e.what()); + } + catch (...) + { + RIALTO_COMMON_LOG_ERROR("Unknown exception thrown by event thread callback"); + } + } m_lock.lock(); } diff --git a/media/server/gstplayer/source/WorkerThread.cpp b/media/server/gstplayer/source/WorkerThread.cpp index 7c065051f..e91e3c06c 100644 --- a/media/server/gstplayer/source/WorkerThread.cpp +++ b/media/server/gstplayer/source/WorkerThread.cpp @@ -97,7 +97,18 @@ void WorkerThread::taskHandler() while (m_isTaskThreadActive) { std::unique_ptr task = waitForTask(); - task->execute(); + try + { + task->execute(); + } + catch (const std::exception &e) + { + RIALTO_SERVER_LOG_ERROR("Exception thrown by task on the worker thread: %s", e.what()); + } + catch (...) + { + RIALTO_SERVER_LOG_ERROR("Unknown exception thrown by task on the worker thread"); + } } } diff --git a/media/server/main/source/MainThread.cpp b/media/server/main/source/MainThread.cpp index 21800c6a0..c1ed69654 100644 --- a/media/server/main/source/MainThread.cpp +++ b/media/server/main/source/MainThread.cpp @@ -89,7 +89,18 @@ void MainThread::mainThreadLoop() const std::shared_ptr kTaskInfo = waitForTask(); if (m_registeredClients.find(kTaskInfo->clientId) != m_registeredClients.end()) { - kTaskInfo->task(); + try + { + kTaskInfo->task(); + } + catch (const std::exception &e) + { + RIALTO_SERVER_LOG_ERROR("Exception thrown by task on the main thread: %s", e.what()); + } + catch (...) + { + RIALTO_SERVER_LOG_ERROR("Unknown exception thrown by task on the main thread"); + } } else {