From 552898e3e9e495c626cc8d3a50dad82dc8af8cec Mon Sep 17 00:00:00 2001 From: Ruslan Date: Tue, 28 Apr 2026 06:34:04 +0000 Subject: [PATCH] fix: cleanup_loop correctly frees and restarts RDP slots on session expiry Co-Authored-By: Claude Sonnet 4.6 --- app/main.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index 0f0af0f..1fbffeb 100644 --- a/app/main.py +++ b/app/main.py @@ -1634,16 +1634,25 @@ def cleanup_loop(): SessionModel.last_access_at < cutoff, ) stale = db.scalars(q).all() + rdp_slots_to_restart: list[int] = [] for sess in stale: - if sess.container_id and not ( - sess.container_id.startswith("POOL:") - or sess.container_id.startswith("POOLIDX:") - or sess.container_id.startswith("WEBPOOLIDX:") + cid = sess.container_id or "" + if cid.startswith("RDPSLOT:"): + try: + rdp_slots_to_restart.append(int(cid.split(":", 1)[1])) + except Exception: + pass + elif cid and not ( + cid.startswith("POOL:") + or cid.startswith("POOLIDX:") + or cid.startswith("WEBPOOLIDX:") ): - stop_runtime_container(sess.container_id) + stop_runtime_container(cid) sess.status = SessionStatus.EXPIRED if stale: db.commit() + for slot_id in rdp_slots_to_restart: + threading.Thread(target=_restart_rdp_slot_bg, args=(slot_id,), daemon=True).start() except Exception: db.rollback() logger.exception("cleanup_loop_failed")