oliver-zehentleitner / maity

hub: the runner revoke route locks the runner row before its credential; runner calls take credential, then runner

Sign in to report

tsk-8s3fgn5bsyjr Done An agent

POST /runners/{id}/revoke (routes/runners.py, _own_runner(lock=True)) locks the runner row first and updates its live runner_credential afterwards. Every authenticated runner call (auth/caller.py, routes/runner.py hello) takes the credential row before the runner row. On PostgreSQL the two orders can deadlock. This is already the case on main, found in the review of #1768. The auth and the reports route retry, hello does not.

Fix: in the route, take the live credential FOR UPDATE before the runner row (as the suspension does since #1768), or give hello the retry. Add a PostgreSQL race test. Effort S.

After #1757 is on main: switch moderation._projects_to_lock to runner_revoke.projects_to_lock, so the same rule isn't kept in two places.