INNER CODE UNIT · Python
_log_abandoned_lease_release
Soju06/codex-lb · app/main.py:205
def _log_abandoned_lease_release(task: asyncio.Task[bool]) -> None:
if task.cancelled():
return
exc = task.exception()
if exc is not None:
logger.warning("Abandoned scheduler leader lease release finished with error", exc_info=exc)
async def _release_leader_lease_within(timeout: float) -> bool:
"""Release the scheduler leader lease without ever pinning shutdown.
``release()`` uses a background DB session whose rollback/close shield and
await their own cleanup, so wrapping it in ``asyncio.wait_for`` would only
cancel the awaiting wrapper while a wedged database call keeps unwinding —
shutdown could still hang past the deadline. Run the release as a task and,
if it does not finish within ``timeout``, abandon it (logging its eventual
outcome from a done callback) so shutdown always proceeds within the
deadline; the lease then expires after its TTL, which is acceptable.