Skip to content

fix(metrics): expire metric-detail leases from the worker event loop - #1834

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/metrics-incarnation-and-lease-tick
Oct 3, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/metrics-incarnation-and-lease-tick

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Fixes #1831

Cause

CAUSE: lib/src/server.rs Server::notify (the only production lease_tick call, reached only from command-channel messages) -> no event-loop path ran the janitor -> SYMPTOM: an abandoned SetMetricDetail lease outlived TTL + 5 s until the next worker command, regardless of data-plane traffic.

Fix

  • The janitor body moves into tick_metric_detail_leases(now) (lib/src/server.rs), called once per Server::run iteration (before send_queue, so the lease_tick_expired event leaves on the same turn) and still from notify (keeps the single clock read shared with lease_apply). lease_tick_due still gates the table walk to once per 5 s. The loop wakes at least once per 1 s poll_timeout, so expiry is bounded by TTL + 5 s + 1 s with no traffic and no command.
  • Docs: lib/src/metrics/mod.rs comments, command.proto lifecycle comment, doc/configure.md (the old "at most one ttl window" was not true), doc/sozu-top.md, CHANGELOG (Unreleased / Fixed).

Regression test

test_abandoned_lease_expires_without_a_command (e2e/src/tests/metrics_lifecycle_tests.rs): real worker, apply a 1 s DETAIL_BACKEND lease, then write nothing more on the command channel while HTTP requests keep flowing; passively read the channel until a lease_tick_expired METRIC_DETAIL_CHANGED event (backend -> cluster) arrives within TTL + 8 s.

  • Red on bd19a78e (unfixed): test ... test_abandoned_lease_expires_without_a_command ... FAILED (stability check FAILED: iteration 1 of 3)
  • Green with fix: test result: ok. 4 passed; 0 failed (all metrics_lifecycle e2e, --features opentelemetry,splice,simd)

Validation

  • cargo +nightly fmt --check -> exit 0
  • cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings -> exit 0
  • RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib -p sozu-command-lib -> exit 0
  • cargo +1.93.1 test -p sozu-command-lib --all-features --locked -> exit 0
  • cargo +1.93.1 test -p sozu-lib --lib --all-features --locked -> 1591 passed, 1 failed: protocol::pipe::tests::splice_readable_eof_drains_kernel_pipe_bytes_before_closing hit its own host precondition guard (splice pipe capacity is 8192 bytes ... exceed fs.pipe-user-pages-soft (16384) ... this is a host limit, not a Sozu regression) on a shared, heavily loaded host; three isolated reruns: pass / same precondition / pass. pipe.rs is untouched here.
  • python3 .github/scripts/check_doc_citations.py --root . --base origin/main -> exit 0
  • Full e2e suite not run locally (left to CI).

#1828 (same-ID cluster incarnation) is deliberately not in this PR: it needs a design decision, see the issue.

The lease janitor ran only at the top of `Server::notify`, which only a
worker command reaches. A lease whose owner disappeared (a crashed
`sozu top`) therefore kept the worker's metric cardinality elevated past
its TTL until the next control request, regardless of data-plane traffic.

Move the janitor into `tick_metric_detail_leases` and call it once per
event-loop iteration, before the response queue is flushed, as well as
from `notify`. The loop wakes at least once per one-second poll timeout,
so an abandoned lease is retired and its `lease_tick_expired` event is
pushed within TTL + 5 s + one poll timeout with no further command.

The new real-worker regression applies a one-second lease, keeps
requests flowing, writes nothing more on the command channel and waits
for the expiry event; it fails on the previous code.

Fixes #1831

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 3fdf940 into main Oct 3, 2026
28 checks passed
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.

Metric-detail leases expire only after another worker command

1 participant