Repository navigation
Description
In short: Every callback of a build is its own
v1-jobsmessage, and each one waits at most 10 s for the deployment lock. With several worker nodes the losers are rejected to the failed list and never retried.Impact:
- Callbacks are lost: missing build log lines, and if it hits
exitorcomplete, a deployment can stay inbuildinguntil someone cancels it.- The failed list grows by hundreds of entries per deploy day and never shrinks (no TTL, see 🐛 Bug Report: Usage queue backlog evicts the cache from Redis #14084).
👟 Reproduction steps
-
Self-hosted Appwrite 2.7.2 with
appwrite-worker-jobson three API nodes (8 coroutines each), one Redis. -
Deploy a site (any framework; our builds take about 100 s).
-
Watch the workers and the failed list:
docker logs -f appwrite-worker-jobs 2>&1 | grep 'Failed to acquire distributed lock' docker exec appwrite-redis redis-cli llen utopia-queue.failed.v1-jobs
👍 Expected behavior
Every callback of a deployment is applied eventually. A worker that does not get the lock requeues the message or waits until the lock is free.
👎 Actual Behavior
During every site build the workers log:
"error.type":"Utopia\\Lock\\Exception\\Contention","error.message":"Failed to acquire distributed lock: jobs-deployment:2:<deploymentId>","span.duration":10.00…
Measured over one week on three nodes:
- 70–100 contentions per node per deploy day, only while builds run.
utopia-queue.failed.v1-jobsgrew by 400–950 entries per deploy day (6 318 in total, allTTL -1).- 141 of 142 deployments reached
ready. One site deployment logged contention only in its first 2.5 minutes, then stayedbuildingfor 25 minutes (buildStartedAt→buildEndedAt1 512 s) until it was canceled. A lostexitorcompletecallback fits this; we could not prove it from the logs.
Cause: Jobs::action() runs each callback inside $locks(Deployments::lock(...), self::LOCK_TTL, ...) with LOCK_TTL = 30 and LOCK_TIMEOUT = 10.0 (Jobs.php L69–L71, L177). The jobs service sends log, artifact, exit and complete callbacks in quick succession, so up to 24 handlers compete for one lock. A handler that gives up throws Contention, the message is rejected and lands in the failed list. Nothing retries it, and the jobs service does not resend because the callback endpoint already answered 204.
Why it matters: a deployment that hangs in building needs a manual cancel and redeploy, and on sites the old deployment keeps serving. Lost log callbacks make build logs incomplete without any sign in the console.
We found no open issue or PR about this.
🎲 Appwrite version
2.7.3 (measured on 2.7.2, code unchanged in 2.7.3)
💻 Operating system
Linux (Ubuntu 26.04), Docker
🧱 Your Environment
Self-hosted, three API nodes and one database node (Postgres 18.7, Redis 7.4, ClickHouse 26.8), sites built through the orchestrator.
💡 Suggested fix
- On
Contention, requeue the message (release) instead of rejecting it, or retry the lock until it is free; the lock is only held for one callback at a time. - Alternatively route all callbacks of one deployment to the same consumer, so that they never compete.
- A test: two handlers for the same deployment, the second must be applied after the first releases the lock, and nothing may end up in the failed list.
👀 Have you spent some time to check if this issue has been raised before?
- I checked and didn't find a similar issue
🏢 Have you read the Code of Conduct?
- I have read the Code of Conduct
Activity
fix(functions): requeue jobs callbacks that lose the deployment lock
fix(functions): requeue jobs callbacks that lose the deployment lock