Repository navigation
Description
What happened
With database.max_connections set to 1, a server stops answering database requests shortly after it starts. /api/v1/ready reports postgres: false and authenticated API calls time out. It stayed that way for the several minutes I watched, and a restart stalls it again.
Three tasks that run at startup take their advisory lock with pglock.TryAcquire, which keeps one of the pool's connections until the task ends, and then query through the same pool. With a pool of one connection, the task's first query waits on the connection its own lock holds, and so does every other query on the server:
generate_extra_stills:Generator.Generateininternal/extrastills/generator.gotakeslockKey(SILOEXT) and then queries throughg.pool.release_stored_artwork:NewStoredArtworkReleaserininternal/metadata/artwork_release.gotakesstoredArtworkReleaseAdvisoryLock(SILORELS) andRunthen queries throughr.pool.cleanup_chapter_thumbnail_originals:OriginalsCleaner.Exclusiveininternal/chapterthumbs/originals_cleanup.gotakesoriginalsCleanupAdvisoryLockand runsfn, whosePagequeries throughc.pool.
This is the same stall #5111 describes for the task history cleanup. #5197 fixes that one by holding the lock on a database session of its own (pglock.TryAcquireSession), and leaves these callers for follow-ups.
Steps to reproduce
Reproduced on a Silo dev deployment built from main at 05b39b6.
- Set
database.max_connectionsto 1 and restart. - Within seconds of startup,
/api/v1/readyreturns 503 withpostgres: false. pg_stat_activityfor the Silo database shows the pool's only connection idle withSELECT pg_try_advisory_lock($1)as its last query, holdingSILOEXT(extra stills).- Give
generate_extra_stillsan empty schedule and restart. The server is ready for a few seconds, then stalls the same way with the connection holdingSILORELS(stored artwork release). - Give
release_stored_artworkandcleanup_chapter_thumbnail_originalsempty schedules too and restart. The server stays ready.
The chapter thumbnail cleanup was confirmed from the source only, since the other two took the connection first in this reproduction.
Expected behavior
Each task runs on a one-connection pool. It could hold its lock on a session outside the pool with pglock.TryAcquireSession once #5197 merges, or run its queries on lock.Conn().
Silo version / commit
main at 05b39b6
Deployment
Any deployment with database.max_connections set to 1, with these tasks on their default schedules.
Clients affected
None directly. Server-side stall.
Relevant logs
time=...Z level=WARN msg="node credential reload failed; keeping the credentials already loaded" component=nodepool error="list node credentials: context deadline exceeded"
pid | state | idle_for | q | locks
-----+-------+-----------------+---------------------------------+------------------
... | idle | 00:02:28.554213 | SELECT pg_try_advisory_lock($1) | 53494c4f455854
Technical notes
This issue follows #5197, which adds pglock.TryAcquireSession. Other pglock.TryAcquire callers listed in #5111's technical notes are still unchecked; these three are the ones that stall a server at startup with no admin action.
Defect: silo-server internal/extrastills/generator.go Generator.Generate
Defect: silo-server internal/metadata/artwork_release.go NewStoredArtworkReleaser
Defect: silo-server internal/chapterthumbs/originals_cleanup.go OriginalsCleaner.Exclusive
AI disclosure
- Harness: Claude Code in T3 Code
- Tools: Claude Code
- Model: claude-opus-5-5
- Involvement: Fully AI-generated
- Independent review: none
Confirmations
- I searched existing issues.
- Reproduced on a real deployment.
Source: found in review of #5197
Activity