Skip to content

Commit 8651a0f

Browse files
author
LittleMouse
committed
[fix] Fix client pool lock.Optimization task paused
1 parent 538b219 commit 8651a0f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

api_server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ async def format_stream():
139139
except asyncio.CancelledError:
140140
logger.warning("Client disconnected early, terminating inference...")
141141
if backend and isinstance(backend, LlmClientBackend):
142-
for task in backend._active_tasks:
143-
task.cancel()
142+
current_task = asyncio.current_task()
143+
if current_task in backend._active_tasks:
144+
current_task.cancel()
144145
raise
145146
finally:
146147
logger.debug("Stream connection closed")

backend/llm_client_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ async def _get_client(self, request):
114114
except asyncio.TimeoutError:
115115
raise RuntimeError("Server busy, please try again later.")
116116
finally:
117-
self._pool_lock.release()
117+
if self._pool_lock.locked():
118+
self._pool_lock.release()
118119

119120
async def _release_client(self, client):
120121
async with self._pool_lock:

0 commit comments

Comments
 (0)