Skip to content

Commit 490d4ee

Browse files
committed
fix: replace threading.Lock with anyio.Lock for Ray deployment compatibility
- Replace threading.Lock() with anyio.Lock() in StreamableHTTPSessionManager - This resolves serialization issues when deploying StreamableHTTP services with Ray - threading.Lock objects cannot be pickled/serialized, causing deployment failures - anyio.Lock provides equivalent functionality while being fully serializable - Update lock usage from 'with' to 'async with' for proper async context
1 parent 6566c08 commit 490d4ee

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/mcp/server/streamable_http_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import contextlib
66
import logging
7-
import threading
87
from collections.abc import AsyncIterator
98
from http import HTTPStatus
109
from typing import Any
@@ -75,7 +74,7 @@ def __init__(
7574
# The task group will be set during lifespan
7675
self._task_group = None
7776
# Thread-safe tracking of run() calls
78-
self._run_lock = threading.Lock()
77+
self._run_lock = anyio.Lock()
7978
self._has_started = False
8079

8180
@contextlib.asynccontextmanager
@@ -97,7 +96,7 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]:
9796
yield
9897
"""
9998
# Thread-safe check to ensure run() is only called once
100-
with self._run_lock:
99+
async with self._run_lock:
101100
if self._has_started:
102101
raise RuntimeError(
103102
"StreamableHTTPSessionManager .run() can only be called "

0 commit comments

Comments
 (0)