Skip to content

Lease expiry is judged by each worker's clock: a worker whose clock runs ahead takes over live leases #45

Open

Description

@waldemort-auto

Summary

fetch_orchestration_item decides whether a lease has expired by comparing locked_until with the caller's p_now_ms. If a worker's clock runs ahead of the lease owner's by more than the time left on the lease, that worker takes the instance over while the owner is still working. With the default 5 s orchestration lock, renewed every 3 s, a 2 s lead is enough.

Since #44 this no longer corrupts data. Renewal and acknowledge are fenced on the lock token, so the old owner's calls fail and no message is processed twice. But the turn runs twice, and the takeover repeats every renewal cycle for as long as the clocks disagree.

Activity and session leases have the same problem in both directions, because they are written and checked with the worker's own clock. A worker whose clock runs behind writes leases that every other worker already sees as expired.

Where (main at 3beba92)

  • migrations/0025_fetch_orchestration_lease_at_claim.sql:
    • expiry checks locked_until > p_now_ms (L78, L93, L118, L133);
    • takeover guards locked_until <= p_now_ms (L159, L174).
  • Activity and session lease procedures: the latest definitions in migrations 0014, 0015 and 0016. They write and compare deadlines with p_now_ms only.

Suggested fix

Trade-offs:

  • This departs from the "Rust-provided timestamps" design of migration 0006.
  • Tests that simulate the future by passing a later p_now_ms will need another way to expire a lease.

Until then

Keep worker clocks within orchestrator_lock_timeout minus the renewal interval of each other: 2 s at the defaults. A longer lock timeout widens this margin.

Evidence

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