diff --git a/src/modules/Playerbot/Performance/ThreadPool/ThreadPool.cpp b/src/modules/Playerbot/Performance/ThreadPool/ThreadPool.cpp index 9dd5ea2c4..00d064cbf 100644 --- a/src/modules/Playerbot/Performance/ThreadPool/ThreadPool.cpp +++ b/src/modules/Playerbot/Performance/ThreadPool/ThreadPool.cpp @@ -270,7 +270,14 @@ void WorkerThread::Run() // NOTE: Cannot use TC_LOG here as it might not be initialized // Error will be recorded in metrics instead _metrics.tasksCompleted.fetch_add(1, ::std::memory_order_relaxed); // Count as completed but failed - if (_diagnostics) + + // CRITICAL FIX: Also update POOL counter to maintain in-flight balance! + // If a task was popped but an exception occurred before RecordTaskCompletion, + // the pool's totalCompleted would never be updated, causing GetInFlightTasks() + // to return a permanently inflated value (leading to "1 in-flight, 0 active workers") + _pool->_metrics.totalCompleted.fetch_add(1, ::std::memory_order_relaxed); + + if (_diagnostics) { _diagnostics->tasksFailed.fetch_add(1, ::std::memory_order_relaxed); } diff --git a/src/modules/Playerbot/Session/BotWorldSessionMgr.cpp b/src/modules/Playerbot/Session/BotWorldSessionMgr.cpp index c8f68643a..3804f793a 100644 --- a/src/modules/Playerbot/Session/BotWorldSessionMgr.cpp +++ b/src/modules/Playerbot/Session/BotWorldSessionMgr.cpp @@ -64,16 +64,25 @@ namespace { ::std::lock_guard lock(_executingTasksMutex); auto now = ::std::chrono::steady_clock::now(); + size_t totalTracked = _executingTasks.size(); + size_t stuckCount = 0; + for (auto const& [guid, task] : _executingTasks) { auto elapsed = ::std::chrono::duration_cast<::std::chrono::milliseconds>(now - task.startTime).count(); if (elapsed > thresholdMs) { + ++stuckCount; TC_LOG_ERROR("module.playerbot.session", "STUCK TASK DETECTED: Bot {} (GUID: {}) has been executing for {}ms!", task.botName, guid.ToString(), elapsed); } } + + // Always log summary for diagnostics + TC_LOG_ERROR("module.playerbot.session", + "LogStuckTasks: {} tasks tracked, {} stuck (>{} ms)", + totalTracked, stuckCount, thresholdMs); } } // anonymous namespace