Skip to content

🐛 Bug Report: Jobs worker stores its dedupe markers (jobs-event-*) in Redis without TTL #15746

Open

Description

@JoshiJoshiJoshi

In short: The jobs worker reads its dedupe markers with a 3600 s TTL but writes them without one, so Redis keeps every marker forever.

Impact:

👟 Reproduction steps

  1. Self-hosted Appwrite 2.7.2, deploy functions or sites for a while.

  2. Count the markers and check their TTL:

    docker exec appwrite-redis redis-cli --scan --pattern 'jobs-event-*' | wc -l
    docker exec appwrite-redis redis-cli ttl "$(docker exec appwrite-redis redis-cli --scan --pattern 'jobs-event-*' | head -1)"

👍 Expected behavior

A marker is removed by Redis after DEDUPE_TTL (3600 s), the window in which the worker uses it.

👎 Actual Behavior

The count only grows, every marker has TTL -1.

Cause: the worker checks a marker with $cache->load($key, self::DEDUPE_TTL) (Jobs.php L180) but stores it with $cache->save($key, true) (L255, L296). The Redis cache adapter only sets EXPIRE when save() gets a TTL; otherwise the envelope only expires logically when it is read. Keys in the format before 2.6.2 (jobs-event-<eventId>, without the project sequence) are never read again and stay as well.

Why it matters: each marker is a small hash (≈ 400 B), but there is one per log, artifact, exit and complete callback of every build. They are never read after an hour, yet they count against maxmemory like the cache and the queues that share the same Redis.

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, Redis 7.4 with --maxmemory-policy allkeys-lru, shared by cache and queues as in the official compose file.

💡 Suggested fix

  • Pass the TTL when saving: $cache->save($key, true, ttl: self::DEDUPE_TTL) at both places.
  • Existing installations keep their old markers; a note in the release (or a one-off cleanup in the migration) would help.

👀 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. utkarshpatwa393-sys commented on Nov 19, 2026

    @utkarshpatwa393-sys

    Hi team! 👋

    I would love to work on this issue.

    Root Cause

    In src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php:

    • Dedupe markers are checked with a TTL window of self::DEDUPE_TTL (3600s) via $cache->load($key, self::DEDUPE_TTL) (L180).
    • However, when writing the markers at lines 255 and 296, $cache->save($key, true) does not pass ttl: self::DEDUPE_TTL.
    • As a result, the Redis cache adapter does not set an expiration (EXPIRE), causing build callback hashes (jobs-event-*) to persist indefinitely in Redis and needlessly consume memory.

    Proposed Solution

    • Pass ttl: self::DEDUPE_TTL to $cache->save($key, true, self::DEDUPE_TTL) at L255 and L296 in Jobs.php.
    • Add test coverage verifying that dedupe marker saves pass self::DEDUPE_TTL.

    Could you please assign this issue to me? Thank you!

  2. saiyyedfardeen commented on Nov 19, 2026

    @saiyyedfardeen
    Contributor

    I have submitted a PR fixing this by passing ttl: self::DEDUPE_TTL (3600s) when saving jobs-event-* markers in Jobs.php, along with unit test coverage: #15839

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