fix: cleanup_loop correctly frees and restarts RDP slots on session expiry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+14
-5
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user