Skip to content

🐛 Bug Report: queue-retry requeues a copy under a new job ID and never deletes the original payload, which stays in Redis without a TTL #14491

Closed

Description

@JoshiJoshiJoshi

👟 Reproduction steps

  1. Self-hosted Appwrite (we measured 2.4.0; the code is unchanged in 2.5.0) with a queue that has failed jobs. We got there by stopping ClickHouse for 120 s while synchronous function executions ran at 50/s: the executions worker writes each execution synchronously, the insert fails, and every execution ends up in utopia-queue.failed.v1-executions (about 6 300 per outage). Any other way to fill a failed list works the same.

  2. Count the payloads of that queue:

    docker exec appwrite-redis redis-cli --scan --pattern 'utopia-queue.jobs.v1-executions.*' | wc -l
    docker exec appwrite-redis redis-cli llen utopia-queue.failed.v1-executions
  3. Retry the failed jobs with the CLI task queue-retry --name=v1-executions (run inside the Appwrite image).

  4. Count again. Check a leftover key: redis-cli ttl utopia-queue.jobs.v1-executions.<pid>.

👍 Expected behavior

After a retry the failed list is empty and the payloads of the retried jobs are cleaned up like the payloads of normal jobs, so Redis memory does not grow because of a retry.

👎 Actual Behavior

The retry works: all executions are processed again and the data is complete. But every retried job leaves its original payload behind. After one retry of a failed list with 13 144 entries (two such outages) we found 13 144 utopia-queue.jobs.v1-executions.* keys with no failed-list entry pointing to them, each ≈ 7 KB, TTL -1. Redis used_memory did not go down after the retry, although the queue was empty again. They had to be deleted by hand.

Cause: retry() pops the pid from the failed list, reads the job and calls requeue(), which pushes a new envelope with a new pid and timestamp (packages/queue/src/Broker/Redis.php L371–L406, L505–L520). The key jobs.<queue>.<old pid> that getJob() read at L385 is never deleted and not given a TTL, and nothing references its pid any more. The CLI task calls this with no other cleanup (QueueRetry.php L55). The same code is on main.

Why it matters: the payload of an execution job is ≈ 7 KB, so 13 000 retried jobs are ≈ 90 MB that nobody will ever read again. The default Redis in the compose file has --maxmemory 512mb --maxmemory-policy allkeys-lru and also holds the cache (see #14084), so these keys displace cache entries and other queue data instead of being evicted first or removed.

The open PR #14243 changes only what the automatic reap() sweep requeues (reapMaxAttempts, reapMaxAge); it does not touch retry(). We found no other open issue or PR for this.

🎲 Appwrite version

2.5.0 (measured on 2.4.0, code unchanged in 2.5.0)

💻 Operating system

Linux (Debian 12), Docker

🧱 Your Environment

Self-hosted Appwrite 2.4.0, Postgres adapter, ClickHouse for usage and executions, Redis 7.4 from the official compose file, queue-retry run inside the worker image.

💡 Suggested fix

  • In retry(), delete jobs.<queue>.<old pid> after the replacement was pushed (or requeue under the same pid and refresh the stored payload).
  • Alternatively give the payload of a failed job a TTL when it is rejected, so leftovers expire by themselves.
  • A test next to the existing recovery tests: publish, reject, retry(), assert that no jobs.<queue>.* key without an owner remains.

👀 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

  1. added
    product / databases
    product / functions
    product / messaging
    product / storage
    product / vcs
    sdk / cli
    on Oct 14, 2026
  2. binoremohapatra commented on Oct 23, 2026

    @binoremohapatra

    Hi team! I've gone through the reproduction steps and the root cause in packages/queue/src/Broker/Redis.php (retry() not cleaning up the old jobs.. key after calling requeue()).

    I would love to work on this and implement the cleanup along with the recovery unit test. Could you please assign this issue to me?

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 / databasesproduct / functionsproduct / messagingproduct / storageproduct / vcssdk / cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions