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,
|
SessionModel.last_access_at < cutoff,
|
||||||
)
|
)
|
||||||
stale = db.scalars(q).all()
|
stale = db.scalars(q).all()
|
||||||
|
rdp_slots_to_restart: list[int] = []
|
||||||
for sess in stale:
|
for sess in stale:
|
||||||
if sess.container_id and not (
|
cid = sess.container_id or ""
|
||||||
sess.container_id.startswith("POOL:")
|
if cid.startswith("RDPSLOT:"):
|
||||||
or sess.container_id.startswith("POOLIDX:")
|
try:
|
||||||
or sess.container_id.startswith("WEBPOOLIDX:")
|
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
|
sess.status = SessionStatus.EXPIRED
|
||||||
if stale:
|
if stale:
|
||||||
db.commit()
|
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:
|
except Exception:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
logger.exception("cleanup_loop_failed")
|
logger.exception("cleanup_loop_failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user