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.
This commit is contained in:
2025-12-13 11:01:58 -05:00
parent f6239f35d6
commit 7f3fc61605

View File

@@ -30,14 +30,18 @@ MCPServer::MCPServer() : _impl(std::make_unique<Impl>())
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();
}
}