Repository navigation
fix(lifecycle): confirm a lost lifecycle lease before renewal stops - #32
Conversation
The heartbeat stopped renewing the first time a coordinator answered False. A coordinator may answer False while the lease is still this worker's, for example when its compare-and-set retries run out under contention, so one busy moment of the store let the lease expire under a long node or core update and another worker could start the node in the middle of it. A False answer is now checked against the coordinator state: renewal continues while the state shows the same epoch, owner and operation and the lease cannot have run out since the last granted renewal. Another owner or epoch, no lease, or a lease that may have expired stops renewal as before.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Takes the interleaving test of upstream 80f81ad (PasarGuard#32) unchanged. The controller part of 80f81ad has been on fork main since d6f43c7, which it was upstreamed from; c1958a8 later made the renewal loop run while the lease token is still registered instead of until the task is cancelling. On fork main the test passes on Python 3.12 and 3.14. With the still-held check removed from _heartbeat_lifecycle_lease it fails: the second worker acquires the lease while the first still renews it.
|
A correction to the impact line of #29, which said that "one busy moment of the shared store" lets a second worker act on the same node. That overstated it. Re-checked on What it really takes:
Lab run (macOS, real nats-server v2.10.25, the panel's real coordinator, the bridge's real lease code; lease 6 s; two runs each). The only thing injected: before each of worker A's next N renewal writes (N as in the table), a separate NATS connection rewrote the same key with its current value, so the real server rejected A's write as a stale revision:
One limit: the fix cannot help when the renewal's own retries outlast the lease. With a 1 s lease and the injection set to 32 conflicts in the same lab, the second worker acquired on c5632b6 too (3/3 runs, at 1.02-1.04 s), because worker A's renewal did not succeed before the stored lease expired. In one run B took over after 31 injected conflicts, while A was still retrying; in one A logged that the lease was still held and kept renewing; in one A had already given up because the lease could have expired ( |
The public part moves from 0.9.2 to 0.10.0 in one step because that is upstream's own release line: upstream v0.10.0 (c5632b6) is a version-only bump over v0.9.5, and every upstream release commit from v0.9.2 to v0.10.0 is now carried here or refused on record. Carried, each re-checked against this tree: PasarGuard#23 maintenance timeouts (b7df83f), every hunk of which that upstream v0.10.0 still has is here; PasarGuard#24 Masque (33276ea, f707f09), all of it except Masque masque = 7, which rides Proxy field 12 because field 7 is Hysteria2 here; PasarGuard#27 rejected-user isolation (67b35df, e4fe5b1, c8b6707), whose sorted changed lines equal a01bdbb's, 934 lines, and which later fork commits build on; PasarGuard#32 lifecycle lease confirmation (d6f43c7), whose _lifecycle_lease_still_held is upstream's line for line while the renewal loop ends on the lease's release rather than on any cancel request; and the WireGuard pre_shared_key of PasarGuard#26 (4ee34d0). Refused on record: the MTProto half of PasarGuard#26, BackendType MTPROTO = 2 and Proxy mtproto = 8, because 2 and 8 are SING_BOX and open_vpn here and the fork has no MTProto backend. Not taken: the bridge's own development uv.lock refresh of v0.9.5; the panel resolves those libraries from its own lock. The local label restarts at singbox.1 on the new public version.
Fixes #29
What
When
coordinator.heartbeat(lease)returnsFalse, the heartbeat now readscoordinator.get_state(node_id)before giving up. It keeps renewing while the state shows the same epoch, owner and operation and the lease cannot have expired yet (measured from the last granted renewal, or from the acquire request). A different owner or epoch, a missing lease, or a lease that may already have expired stops renewal and logs "was lost" as before.tests/test_maintenance.py:LostLeaseCoordinatornow releases the lease when it reports it lost, so that test still checks a real loss.Why
See the issue. A coordinator can answer
Falsewithout the lease being gone (the panel's NATS coordinator does this when its compare-and-set retries are exhausted). Stopping renewal on that answer lets the lease expire in the middle of a long update, and a second worker then acts on the same node.Relation to #18
The open PR #18 also treats a
Falseheartbeat as a lost lease: it turns it intoLifecycleLeaseLostError. This PR changes exactly that interpretation:Falsealone is no longer taken as proof of loss; the stored state decides. If #18 lands first, itsFalsebranch should consult the stored state in the same way.Tests
tests/test_lifecycle_heartbeat.py:test_an_unconfirmed_renewal_while_the_lease_is_still_held_keeps_renewing, a renewal answeredFalsewhile the lease is still held keeps renewing, so no other worker can take the lease mid-update.tests/test_maintenance.py: a lease that is really lost still stops renewal.tests/test_lifecycle_lease_interleave.py:test_two_workers_never_both_renew_one_lease, two workers on one node; the second must be rejected on all twelve acquire attempts while the first is still updating.Before the fix (v0.9.4):
After the fix, the full suite (
python -m unittest tests.test_lifecycle_heartbeat tests.test_lifecycle_lease_interleave tests.test_maintenance tests.test_storage tests.test_sync_transport tests.test_user_sync):Ran 75 tests in 34.134sOK.