From 0b1f2a2fc614c2e7a2218514fe16e85c4d4e48e1 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Fri, 5 Dec 2025 11:44:42 +0100 Subject: catch exception leaks in windows thread pool (#677) * catch exception leaks in windows thread pool * make non-assert exception an error, assert is kept as warning as it is already reported --- CHANGELOG.md | 1 + src/zencore/workthreadpool.cpp | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1742903a6..7468c6197 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## - Improvement: Refactored cache batch fetch operations to not do complex execution in destructor of PutBatch and GetBatch classes +- Improvement: Stop unhandled exceptions from async work in windows threadpool - Bugfix: Fixed warning due to calling std::filesystem::equivalent on a non-existing path ## 5.7.13 diff --git a/src/zencore/workthreadpool.cpp b/src/zencore/workthreadpool.cpp index e241c0de8..cb84bbe06 100644 --- a/src/zencore/workthreadpool.cpp +++ b/src/zencore/workthreadpool.cpp @@ -156,8 +156,22 @@ struct WorkerThreadPool::Impl m_WorkQueue.pop_front(); } - ZEN_TRACE_CPU_FLUSH("AsyncWork"); - WorkFromQueue->Execute(); + try + { + ZEN_TRACE_CPU_FLUSH("AsyncWork"); + WorkFromQueue->Execute(); + WorkFromQueue = {}; + } + catch (const AssertException& Ex) + { + WorkFromQueue = {}; + ZEN_WARN("Assert exception in worker thread: {}", Ex.FullDescription()); + } + catch (const std::exception& e) + { + WorkFromQueue = {}; + ZEN_ERROR("Caught exception when executing worker synchronously: {}", e.what()); + } } }; @@ -264,7 +278,7 @@ WorkerThreadPool::Impl::WorkerThreadFunction(ThreadStartInfo Info) catch (const std::exception& e) { Work = {}; - ZEN_WARN("Caught exception in worker thread: {}", e.what()); + ZEN_ERROR("Caught exception in worker thread: {}", e.what()); } } else @@ -319,7 +333,7 @@ WorkerThreadPool::ScheduleWork(Ref Work, EMode Mode) catch (const std::exception& e) { Work = {}; - ZEN_WARN("Caught exception when executing worker synchronously: {}", e.what()); + ZEN_ERROR("Caught exception when executing worker synchronously: {}", e.what()); } } -- cgit v1.2.3