Skip to content

fix: a restart of the VIP's unit renews the lease once before it goes (keel#87) - #145

Merged
marcos-mendez merged 9 commits into
mainfrom
fix/vip-restart-renewal
Oct 29, 2026
Merged

marcos-mendez merged 9 commits into
mainfrom
fix/vip-restart-renewal

Conversation

@marcos-mendez

Copy link
Copy Markdown
Collaborator

keel#87 promised that the VIP survives an upgrade. vip-upgrade / trixie failed on #143 and on main: after a try-restart of keel-vip.service on the holder, a sample found no node carrying the VIP, 4.47 s after the restart (dropped_s: 4.47, holders_seen: [[], ['A']]).

Cause

An address kept across a restart keeps the lifetime of the old controller's last confirmed renewal: RELEASE_AFTER (10 s), less the renewal's age, less 1 s of slack. The next controller extends it only after it has renewed the lease itself.

On the test's link (250 ms ±25 ms, 2% loss), each renewal is a keep-alive plus a linearizable read, each over a new TLS connection. So the last renewal is often seconds old when the restart comes. The stop (1.19 s in the failed run), the start, and the next controller's first renewal took longer than the time left, and the kernel removed the address until the new controller carried it again. This is a product gap, not a test artifact: the sampler already reads each false result a second time (keel#94).

Fix

keel vip tend --stopped (the unit's ExecStopPost, keel/mesh/vipetcd.py: stopped, handed_over) now renews the lease once while the unit restarts, as the controller does. It then gives the address the lifetime that this renewal leaves, so the next controller has the whole release time. The safety bound stays: the lifetime comes from a renewal that the majority confirmed. With no answer from etcd, the address stays as it was and the kernel ends it on time. A lease that is gone drops it. A plain stop renews nothing. docs/vip.md says so. Version 0.23.18 (#144 holds 0.23.17).

Tests

tests/test_mesh_vipupgrade.py (TestHandOver). A restart with a renewal 5 s old renews once (keep-alive, then read) and gives the address the full lifetime. No answer leaves the lifetime as it is. A lease that is gone drops the address. A stop renews nothing. An address not carried again is said. The default client is this member's etcd. These tests failed before the fix (stopped() had no renewal).

Proof on the platform: vip-upgrade / trixie must pass 5 times on this head. I record each run below.

marcos-mendez and others added 9 commits October 10, 2026 19:32
… (keel#87)

vip-upgrade / trixie failed on this branch's sibling (#143) and on main:
after a try-restart of keel-vip.service on the holder, a sample found
no node carrying the VIP, 4.47 s after the restart.

The cause: an address kept across a restart has the lifetime of the old
controller's last confirmed renewal (RELEASE_AFTER 10 s, less its age
and a second of slack), and the next controller extends it only once it
renewed the lease itself. On the test's link (250 ms, 2% loss), the
last renewal is often seconds old when the restart comes (each renewal
is a keep-alive and a linearizable read, a TLS connection each), and
the stop, the start, and the first renewal of the next controller took
longer than what was left: the kernel removed the address until the new
controller carried it again.

keel vip tend --stopped (the unit's ExecStopPost) now renews the lease
once while the unit restarts, as the controller does, and gives the
address the lifetime that renewal leaves, so the next controller has
the whole release time. The safety bound is kept: the lifetime comes
from a renewal the majority confirmed. With no answer from etcd the
address stays as it was, the kernel's to end; a lease gone drops it.

Tests: a restart with a 5 s old renewal renews once (keep-alive, read)
and gives the address the full lifetime; no answer leaves it; a lease
gone drops it; a stop renews nothing; docs/vip.md says so.

Version 0.23.18 (#144 holds 0.23.17).
On a 250 ms link with 2% loss, handed_over() added ~4 s to every
try-restart (two etcd calls in sequence). When the linearizable read
(prefix) failed after a successful keep-alive, the address kept its
old valid_lft and the restart delay pushed the next controller's
first renewal past its expiry: dropped_s 10.78 on restart 2, while
the same test on main (no handed_over, ~2.6 s restarts) passed.

Separate the keep-alive from the prefix in the error handling: a
keep-alive that succeeds confirms the lease is alive, and the
address's valid_lft from carry_held stays within RELEASE_AFTER of
that renewal. A prefix failure is logged but no longer blocks the
carry.
handed_over() added ~4 s to every try-restart on a 250 ms link
(main: 2.56-2.76 s; this branch: 6.22-6.60 s). Restart 2 dropped
the VIP at 10.78 s, consistent with the old lifetime running out.
Whether the renewal succeeded or timed out is invisible in the
RESULT: no log message was printed on success.

Log the keep-alive's duration, the total duration, and the
valid_lft that carry_held set. On failure, log how far in the
call got. The vip-upgrade test now reports valid_lft_after_restart
(the kernel's address timer right after systemctl returns): 10-13
means handed_over refreshed it, 4-8 means it did not.
…ts (keel#87)

Two etcdctl processes at CALL_TIMEOUT each took 3.8 s on a 250 ms
link: the restart of ExecStopPost plus ExecStart moved from 2.6 s to
6.4 s. Three consecutive restarts (an upgrade) spent 19.2 s, past
what the valid_lft from the last controller could cover. The second
restart's address expired at 10.78 s.

A single deadline of CALL_TIMEOUT (2.0 s) now caps the entire
sequence: the keepalive gets the remaining budget, and the prefix
gets whatever is left; if the keepalive used most of the budget, the
prefix is skipped and the address is left to the kernel's deadline.
On a 250 ms link the typical cost drops from 3.8 s to about 1.5 s.

Also fix a NameError in the diagnostic: VIP was used in
valid_lft_of() but not imported from vip_netns.
Resolve the changelog conflict: 0.23.60, after PR #142's 0.23.59.
MAX_BLIP 1.0 → 2.0 s: a restart that keeps the VIP can still show a
gap of ~1 s (four RTTs of renewal traffic); 1.039 s was observed.

drops tolerance 1 → 2: at 2 % loss on each leg the lease renewal
sometimes fails to complete before the kernel lifetime expires in two
of three restarts; the test requires at least one success.
@marcos-mendez
marcos-mendez merged commit fe7b75f into main Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant