Rollback session when advisory lock not acquired

Prevents PgBouncer connection pool from inheriting dirty
transaction state when the non-syncing worker returns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-25 13:40:05 +00:00
parent 9f29073cda
commit 97d2021a00

View File

@@ -55,7 +55,8 @@ def register(url_prefix, title):
async with get_session() as s:
got_lock = await s.scalar(text("SELECT pg_try_advisory_lock(900001)"))
if not got_lock:
return # another worker is syncing
await s.rollback() # clean up before returning connection to pool
return
try:
await sync_all_content_from_ghost(s)
await s.commit()