Skip to content

Commit 90b6595

Browse files
rapsealkachimnol
authored andcommitted
fix: Enable exhaustive search for recursive session termination (#1617)
Backported-from: main Backported-to: 23.03
1 parent 0e55ace commit 90b6595

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

changes/1617.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enable exhaustive search for recursive session termination irrelevant to each session's status

src/ai/backend/manager/api/session.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,27 +1152,34 @@ async def destroy(request: web.Request, params: Any) -> web.Response:
11521152
if params["recursive"]:
11531153
async with root_ctx.db.begin_readonly_session() as db_sess:
11541154
dependent_session_ids = await find_dependent_sessions(
1155-
session_name, db_sess, owner_access_key
1155+
session_name,
1156+
db_sess,
1157+
owner_access_key,
1158+
allow_stale=True,
11561159
)
11571160

11581161
target_session_references: List[str | uuid.UUID] = [
11591162
*dependent_session_ids,
11601163
session_name,
11611164
]
1162-
sessions = [
1163-
await SessionRow.get_session(
1164-
db_sess,
1165-
name_or_id,
1166-
owner_access_key,
1167-
kernel_loading_strategy=KernelLoadingStrategy.ALL_KERNELS,
1168-
)
1169-
for name_or_id in target_session_references
1170-
]
1165+
sessions: Iterable[SessionRow | Exception] = await asyncio.gather(
1166+
*[
1167+
SessionRow.get_session(
1168+
db_sess,
1169+
name_or_id,
1170+
owner_access_key,
1171+
kernel_loading_strategy=KernelLoadingStrategy.ALL_KERNELS,
1172+
)
1173+
for name_or_id in target_session_references
1174+
],
1175+
return_exceptions=True,
1176+
)
11711177

11721178
last_stats = await asyncio.gather(
11731179
*[
11741180
root_ctx.registry.destroy_session(sess, forced=params["forced"])
11751181
for sess in sessions
1182+
if isinstance(sess, SessionRow)
11761183
],
11771184
return_exceptions=True,
11781185
)
@@ -1570,6 +1577,8 @@ async def find_dependent_sessions(
15701577
root_session_name_or_id: str | uuid.UUID,
15711578
db_session: SASession,
15721579
access_key: AccessKey,
1580+
*,
1581+
allow_stale: bool = False,
15731582
) -> Set[uuid.UUID]:
15741583
async def _find_dependent_sessions(session_id: uuid.UUID) -> Set[uuid.UUID]:
15751584
result = await db_session.execute(
@@ -1588,7 +1597,10 @@ async def _find_dependent_sessions(session_id: uuid.UUID) -> Set[uuid.UUID]:
15881597
return dependent_sessions
15891598

15901599
root_session = await SessionRow.get_session(
1591-
db_session, root_session_name_or_id, access_key=access_key
1600+
db_session,
1601+
root_session_name_or_id,
1602+
access_key=access_key,
1603+
allow_stale=allow_stale,
15921604
)
15931605
return await _find_dependent_sessions(cast(uuid.UUID, root_session.id))
15941606

src/ai/backend/manager/api/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ async def call_non_bursty(
324324
Execute a coroutine once upon max_bursts bursty invocations or max_idle
325325
milliseconds after bursts smaller than max_bursts.
326326
"""
327-
global _burst_last_call, _burst_calls, _burst_counts
327+
global _burst_last_call, _burst_times, _burst_counts
328328
if inspect.iscoroutine(coro):
329329
# Coroutine objects may not be called before garbage-collected
330330
# as this function throttles the frequency of invocation.

0 commit comments

Comments
 (0)