From 7f3fc61605a3e645d1bb7d62cac8a921ebefa2e5 Mon Sep 17 00:00:00 2001 From: James Huston Date: Sat, 13 Dec 2025 11:01:58 -0500 Subject: [PATCH] fix(mcp): Fix MCPServer shutdown crash - proper thread cleanup in destructor The destructor was calling Shutdown() which accesses other singletons that may already be destroyed during static destruction. Now the destructor only handles thread cleanup directly without accessing other singletons. --- src/araxiaonline/mcp/AraxiaMCPServer.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/araxiaonline/mcp/AraxiaMCPServer.cpp b/src/araxiaonline/mcp/AraxiaMCPServer.cpp index 908cb07cf1..3137ed75d1 100644 --- a/src/araxiaonline/mcp/AraxiaMCPServer.cpp +++ b/src/araxiaonline/mcp/AraxiaMCPServer.cpp @@ -30,14 +30,18 @@ MCPServer::MCPServer() : _impl(std::make_unique()) MCPServer::~MCPServer() { // Note: During static destruction, other singletons may already be destroyed. - // We need to be careful not to access them. - try + // Shutdown() should have been called from World::~World() already. + // Just ensure the thread is properly cleaned up. + if (_serverThread) { - Shutdown(); - } - catch (...) - { - // Swallow any exceptions during destruction + if (_serverThread->joinable()) + { + // Thread still running - try to stop it + if (_impl) + _impl->server.stop(); + _serverThread->join(); + } + _serverThread.reset(); } }