Skip to content

refactor(redis): the monitoring and operator-queue leader leases release with GET-then-DELETE #4253

Open

Description

@AndriiPasternak31

Problem

MonitoringService._release_leadership (services/monitoring_service.py:999, monitoring:leader) and the operator-queue poller's _release_leadership (services/operator_queue_service/poller.py:139, opqueue:leader) do this:

if r.get(KEY) == self._worker_id:
    r.delete(KEY)

If our lease lapses after the GET and a sibling worker wins SET NX, the DELETE removes the sibling's lease. A third worker can then acquire while the sibling still believes it leads, so two cycles run at once. The canary leader lease closed this window for itself in #1881, and its comment (services/canary_service.py, the lease block) names these two leases as sharing the old shape.

With trinity#4028 (PR #4251) the atomic release script has one home: redis_breaker_util.LEASE_RELEASE_LUA, which the canary also uses.

What must be true

  • Neither leader-lease release can delete a sibling's lease, including when the sibling wins between a client-side read and the delete.
  • Their refresh, if they have one, gets the same check.
  • Tested against an executing-script emulator, not a Python copy of the compare.

Activity

  1. added
    priority-p3
    type-refactor
    theme-reliability
    complexity-low
    on Nov 4, 2026
  2. AndriiPasternak31 commented on Nov 4, 2026

    @AndriiPasternak31
    ContributorAuthor

    One more lease with the same race, found while reviewing #4251: the sync-health poll lease (src/backend/services/sync_health_service.py). It keeps its own copy of the release script, and its refresh is GET-then-EXPIRE (around lines 458-459), so a stale worker can re-arm its successor's lease and both act as leader. It fits here with the other leader leases.

  3. vybe commented on Nov 5, 2026

    @vybe
    Contributor

    Adding one more lease to this issue's scope. PR #4251's description says the sync-health poll lease belongs here, and this issue's text did not mention it: services/sync_health_service.py keeps its own copy of the release script, and its refresh is GET-then-EXPIRE. That is the same race #4028 closes for SingleFlightLock, so it should move to the shared scripts with the two leader leases.

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

    complexity-lowpriority-p3theme-reliabilitytype-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions