Repository navigation
Description
What happened
With database.max_connections set to 1, the task history cleanup stalls every database request on the server that runs it. PgExecutionRepository.Prune (internal/taskmanager/repository/postgres_history.go) takes its advisory lock with pglock.TryAcquire, which holds one of the pool's connections until the prune ends. It then runs its queries through that same pool, starting with listTaskKeys (r.pool.Query). With a one-connection pool, that query waits for the connection the lock is holding. It never gets it, so the prune and every other query on the server wait until the run's context is cancelled.
The setting accepts values down to 1 (normalizeAdminInt(key, value, 1, 10000) in internal/config/admin_settings.go, also settable through SILO_DB_MAX_CONNECTIONS), and the server supports a pool of that size elsewhere on purpose. The default of 20 doesn't hit this.
Steps to reproduce
Not reproduced live. Found by tracing the source on main at 1d6a023.
- Set
database.max_connectionsto 1. - Let the task history cleanup run, or start it.
Prunetakes the lock, and theSELECT DISTINCT task_keyquery that follows never gets a connection.
#5110 fixed the same stall for the cluster task lock (advisoryClusterLock). Its test opens a one-connection pool, holds the lock, and runs a pool query. On unfixed code that query hits its deadline, and the same harness applies here.
Expected behavior
The prune runs on a one-connection pool. It could hold the lock on its own session outside the pool, as #5110 does and as downloads.ArtifactRepository.WithMaintenanceLock already does, or run its queries on lock.Conn().
Silo version / commit
main at 1d6a023
Deployment
Any deployment with database.max_connections set to 1.
Clients affected
None directly. Server-side stall.
Relevant logs
No logs available.
Technical notes
Other pglock.TryAcquire callers that query the pool while they hold the lock may have the same stall. They are unchecked. Candidates: catalog search index maintenance, recommendations jobs, trickplay reconcile, storagetransition, metadata artwork release and storage sweep, chapterthumbs originals cleanup, extrastills, audiobooks author counts, and adminjob library refresh. Callers that do their work on lock.Conn(), such as the blob GC sweep, are unaffected. The playback plan store's session lock (planstore.Postgres.AcquireSessionLock) sizes its capacity as MaxConns/2 with a floor of 1. At a pool of 1 it pins the only connection while it issues store queries. That is also unchecked.
Defect: silo-server internal/taskmanager/repository PgExecutionRepository.Prune
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 #4642
Activity
Quick104 commentedon Nov 22, 2026
One more candidate from the #5110 review:
requestReconcileLocker(internal/taskmanager/tasks/reconcile_requests.go) takesrequestTargetWriteAdvisoryLockwithpglock.TryAcquireand holds the pooled connection while it waits. The download refresh task takes the same key, so at a pool size of 1 the two tasks may stall each other. Not checked against the source yet.Rhainland commentedon Nov 23, 2026
Reproduced on
origin/mainat 3b2b321: withSILO_DB_MAX_CONNECTIONS=1, running Database Maintenance (which runs the task history cleanup) made/api/v1/readyreportpostgres: falseand authenticated API calls time out. The cleanup's advisory lock stayed on the pool's only connection while the cleanup sat idle.Cause:
Pruneheld its lock on a pooled connection and then queried through the same pool, so its first query waited on itself and every other query waited behind it.Fix in #5197: the cleanup holds its lock on a separate database session, as the cluster task lock does since #5110, so the server keeps answering while it runs. Checked on a local build of the fix: the same steps on the same database keep
/api/v1/readyat 200, the cleanup deletes the 500 expired rows, and no lock is left held. A new database test runs the prune on a one-connection pool and checks that it still skips while another server holds the lock.Separately, at a pool size of 1 two other tasks stall the server at startup on their own:
generate_extra_stills(internal/extrastills) andcleanup_chapter_thumbnail_originals(internal/chapterthumbs) both hold the pool's only connection throughpglock.TryAcquirewhile they query the pool. They are not part of this fix.AI disclosure: reproduced and fixed by Claude Code (claude-opus-5-5) at the maintainer's direction.
fix(taskmanager): keep task history cleanup from stalling a one-conne…