Skip to content

Lifecycle lease heartbeat stops renewing on the first False, even when the coordinator still shows the lease as ours #29

Closed

Description

@Free-Guy-IR

Summary

Controller._heartbeat_lifecycle_lease returns on the first renewed is False from coordinator.heartbeat(lease) without checking whether the lease is actually gone. A coordinator can answer False while the lease is still held (for example when its compare-and-set retries run out under contention). Renewal then stops, the lease expires in the middle of a long operation (node update, core update), and another worker can acquire it and act on the same node concurrently.

Impact

During a multi-minute node or core update, one busy moment of the shared store lets a second worker start, stop or update the same node while the first operation is still running.

Affected versions

v0.9.4 (f892a5ccb6cff597ec233854dea7abc46981d1bb). The shared-storage branch head (c82f1d5aa3e04c47ef9bb70cae4fc43c2dbc3f4f) ignores the return value of heartbeat() entirely, so it does not stop on False.

Reproduction

  1. Use a lifecycle coordinator whose first heartbeat() calls return False while the stored lease token is still this worker's (later heartbeats succeed).
  2. Start node.update_node() with lifecycle_lease_seconds=0.6 against a node whose update takes 1.6 s.
  3. A second worker on the same node calls _acquire_lifecycle_lease(START) every 0.1 s.

On v0.9.4 the second worker gets the lease while the first update is still running:

FAIL: test_two_workers_never_both_renew_one_lease
AssertionError: second worker acquired while the first still renewed

Where it happens in practice

The panel's NATS coordinator (app/node/nats_memory.py, heartbeat()) retries the compare-and-set 32 times and, if every attempt loses the race, logs "Lifecycle heartbeat CAS exhausted" and returns False, although the stored token still matched this lease. The bundled in-memory coordinator returns False only on a real token mismatch.

Root cause

PasarGuardNodeBridge/controller.py:418-434: on renewed is False (:432) the heartbeat logs "was lost" and returns without reading the coordinator state.

Proposed fix

On False, read coordinator.get_state(node_id) and keep renewing while it shows the same epoch, owner and operation and the lease cannot have expired yet. A PR follows.

Related: the open PR #18 also treats a False heartbeat as a lost lease (it raises LifecycleLeaseLostError), which is the behaviour this change revisits.

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