Skip to content

lablink_allocator_service.admin_session_expiry

Admin-session expiry sweep.

Periodically releases VMs an admin reserved for troubleshooting (admin_reserve_vm) but never explicitly released, so an admin closing the /desktop tab without clicking "Release" doesn't leave the VM stuck out of the assignable pool forever. This is a fixed-duration safety net, not activity-based idle detection — the allocator has no visibility into whether the admin's VNC WebSocket is still open once nginx's auth_request handshake has succeeded once.

Background service that releases expired admin VM reservations.

Parameters:

Name Type Description Default
database VmDatabase

VmDatabase instance for querying/updating VM state.

required
timeout_minutes int

Age, in minutes, past which a reservation is considered expired and force-released.

30
check_interval_seconds int

How often to sweep for expired reservations.

300
Source code in packages/allocator/src/lablink_allocator_service/admin_session_expiry.py
def __init__(
    self,
    database: VmDatabase,
    timeout_minutes: int = 30,
    check_interval_seconds: int = 300,
):
    self.database = database
    self.timeout_minutes = timeout_minutes
    self.check_interval_seconds = check_interval_seconds
    self._stop_event = Event()
    self._thread = None

Start the sweep thread.

Source code in packages/allocator/src/lablink_allocator_service/admin_session_expiry.py
def start(self):
    """Start the sweep thread."""
    self._stop_event.clear()
    self._thread = Thread(target=self._run, daemon=True)
    self._thread.start()
    logger.info(
        "Admin-session expiry service started (interval=%ss, timeout=%sm)",
        self.check_interval_seconds, self.timeout_minutes,
    )

Stop the sweep thread.

Source code in packages/allocator/src/lablink_allocator_service/admin_session_expiry.py
def stop(self):
    """Stop the sweep thread."""
    self._stop_event.set()
    if self._thread:
        self._thread.join(timeout=10)
    logger.info("Admin-session expiry service stopped")