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")