-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Thread unsafe singleton pattern in MCPManager #812
Copy link
Copy link
Open
Description
Description
The MCPManager class in qwen_agent/tools/mcp_manager.py uses a singleton pattern that is not thread-safe:
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(MCPManager, cls).__new__(cls, *args, **kwargs)
return cls._instanceIn a multi-threaded environment (e.g., when serving multiple users via Gradio WebUI or any ASGI server), two threads can both evaluate cls._instance is None as True simultaneously, resulting in two separate instances being created. This breaks the singleton guarantee and can lead to duplicated MCP server connections, inconsistent state, or resource leaks.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels