Skip to content

🐛 Bug Report: Failed queue jobs never expire and there is no way to purge them #15747

Open

Description

@JoshiJoshiJoshi

In short: A rejected job keeps its payload in Redis with no TTL, and nothing ever removes failed jobs. queue-retry is the only tool, and it brings back jobs of any age.

Impact:

👟 Reproduction steps

  1. Self-hosted Appwrite 2.7.2. Make any queue reject jobs, e.g. stop ClickHouse for a minute while usage is written, or deploy sites on several nodes (lock contention in v1-jobs, separate issue).

  2. Check the failed list and a payload:

    docker exec appwrite-redis redis-cli llen utopia-queue.failed.v1-stats-usage
    pid=$(docker exec appwrite-redis redis-cli lindex utopia-queue.failed.v1-stats-usage -1)
    docker exec appwrite-redis redis-cli ttl utopia-queue.jobs.v1-stats-usage.$pid

👍 Expected behavior

Failed jobs are kept for a bounded time for inspection and queue-retry, then removed, or there is a task to purge failed jobs older than a given age.

👎 Actual Behavior

The failed lists only grow; every payload has TTL -1. Our oldest entries are four weeks old.

Cause: on reject, settle.lua pushes the pid onto utopia-queue.failed.<queue>, keeps the payload in utopia-queue.jobs.<queue>.<pid> and only sets EXPIRE when the queue's jobTtl is greater than 0 (settle.lua L28–L29). The worker server builds its queues with new Queue($queueName, $namespace) (Server.php L525), so jobTtl is 0 (Queue.php L12). maintain()/reap() only handle stuck claims, and the maintenance task does not touch queues.

The CLI does not help either:

Why it matters: an operator cannot see, bound or clean up failed jobs without writing Redis scripts, and the only safe way to delete them is pid by pid (LREM plus DEL of the payload), because the payloads of running jobs share the same key prefix.

Related: #14084 (Redis eviction), #14491 (payloads left by queue-retry, fixed in 2.7.2).

🎲 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, Redis 7.4 with allkeys-lru shared by cache and queues.

💡 Suggested fix

  • Give worker queues a retention for failed jobs (e.g. jobTtl of 7 days for the payload, and trim the failed list in maintain()), configurable by an environment variable.
  • Add queue-purge --name=<queue> --older-than=<days> next to queue-retry, and an age filter for queue-retry (the broker's retry() already supports newerThan).
  • Fix or remove bin/queue-count-failed.

👀 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

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions