Skip to content

🐛 Bug Report: Jobs worker drops deployment callbacks on lock contention, a deployment can hang in building #15745

Open

Description

@JoshiJoshiJoshi

In short: Every callback of a build is its own v1-jobs message, 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:

👟 Reproduction steps

  1. Self-hosted Appwrite 2.7.2 with appwrite-worker-jobs on three API nodes (8 coroutines each), one Redis.

  2. Deploy a site (any framework; our builds take about 100 s).

  3. 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-jobs grew by 400–950 entries per deploy day (6 318 in total, all TTL -1).
  • 141 of 142 deployments reached ready. One site deployment logged contention only in its first 2.5 minutes, then stayed building for 25 minutes (buildStartedAt → buildEndedAt 1 512 s) until it was canceled. A lost exit or complete callback 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / functions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions