Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,20 @@ async def _mcp_session_runner() -> None:
)

# Wait for the background task to finish initialisation.
await ready_event.wait()
try:
await asyncio.wait_for(ready_event.wait(), timeout=30)
except asyncio.TimeoutError:
task.cancel()
try:
await task
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The timeout path can still hang because it awaits the cancelled MCP task without any second timeout.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/chainlit/server.py, line 1490:

<comment>The timeout path can still hang because it awaits the cancelled MCP task without any second timeout.</comment>

<file context>
@@ -1482,7 +1482,20 @@ async def _mcp_session_runner() -> None:
+    except asyncio.TimeoutError:
+        task.cancel()
+        try:
+            await task
+        except BaseException:
+            pass
</file context>

except BaseException:
pass
return JSONResponse(
status_code=504,
content={
"detail": f"MCP connection to '{payload.name}' timed out during initialization"
},
)

if "error" in result_holder:
# The task already exited and cleaned up its exit stack.
Expand Down