Skip to content

[daily-ci] FLAKY-TEST: TTL expiration during forkless bgsave computes expiry deadlines from a pre-loop timestamp #49

Closed

Description

@madolson

TTL expiration during forkless bgsave sets TTLs with 1200 synchronous EXPIRE round trips but computes every expiry deadline from a timestamp captured before that loop starts, so the test's idea of when a key dies drifts from reality by however long the loop takes. For keys whose index is a multiple of 10 the built-in slack is exactly one second, and reaching key 90 costs roughly 1080 round trips, so any environment slower than ~0.9 ms per round trip fails the "must be gone" assertion. That is a test bug, not a forkless-save bug: lost expire metadata would fail deterministically at key 0 on every platform, and this fired in 1 of 7 daily runs. Upstream valkey-io#4611 tracks the symptom without a root cause; this agrees with it and adds the cause.

Details

Job

Assertion

Expected '1' to be equal to '0' (context: type eval line 56 cmd {assert_equal [r exists before_${i}] 0} proc ::test)

assert_equal {value expected} formats as "Expected '$value' to be equal to '$expected'" (tests/support/test.tcl:55-58), so EXISTS before_$i returned 1. Relative line 56 resolves to tests/integration/rdb.tcl:1063 (body starts at 1009), the "expired for more than 2 seconds" branch.

The arithmetic

tests/integration/rdb.tcl:1008-1080:

  • 1015: set start_time [clock milliseconds], taken before any TTL is set.
  • 1016-1021: 100 keys x 12 prefixes = 1200 synchronous EXPIRE calls, ttl = $i/10 + 1 (integer division, 1017).
  • 1062: gone-threshold is elapsed_time > $i/10.0 + 2, measured from start_time.

Assumed expiry: start_time + i/10 + 1. Real expiry: t_expire(i) + floor(i/10) + 1, where t_expire(i) is wall time from start_time until key i's EXPIREs execute (12 * i round trips in).

margin(i) = (i/10 - floor(i/10)) + 1 - t_expire(i)

For i % 10 == 0 the fractional term is 0, so margin is 1 s - t_expire(i). t_expire(90) is ~1080 round trips. 16 parallel clients on 32-bit Alpine, or ASan, blow past 0.9 ms per round trip.

Second, independent flaw: elapsed_time is sampled once per outer pass (1053) and then up to 1200 EXISTS commands run against that stale sample (1055-1077). That one biases the opposite branch (1057-1068, "not yet expired, must exist"), so it is not what failed here, but it will fail the same way.

Ruled out as a real defect

  • Lost or broken expire metadata in the forkless snapshot would make keys immortal and fail at i = 0 (elapsed 2 s) on every platform every run. Observed: 1 of 7 daily runs, one job.
  • Expires survive the snapshot as absolute times. tests/integration/rdb.tcl:383-418 asserts keys already expired at save time are still serialized into the RDB, and load drops them on a primary. Nothing re-bases a TTL relative to load time, so debug reload nosave at 1030 cannot push an expiry past the threshold.
  • catch {r debug reload nosave} swallowing a failure leaves the in-memory dataset with the same absolute expires, so that path changes nothing either.

Introduced by

acba5ddd0 "Forkless Save (valkey-io#4460)", 2026-09-03, which added the test. git log -S 'TTL expiration during forkless bgsave' -- tests/integration/rdb.tcl returns only that commit.

Fix direction

Compute each key's deadline at the moment its EXPIRE runs, or use EXPIREAT with absolute timestamps derived from start_time, and re-sample clock milliseconds inside the foreach instead of once per outer pass.

This was generated by AI but verified, with love, by a human.

Activity

  1. added
    bug
    on Sep 16, 2026
  2. madolson commented on Sep 16, 2026

    @madolson
    OwnerAuthor

    Duplicate of valkey-io#4611, which the Valkeyrie Ops test-failure detector already tracks for this exact test. The reproduction is on that issue instead: valkey-io#4611 (comment).

    Short version, since this issue's analysis was right about the cause: the forcing knob is per-command latency, ./runtest --single integration/rdb --loops 5 --config appendonly yes --config appendfsync always, which stretches the 1200-round-trip EXPIRE loop from 0.041 s to 3.36 s and fails 5 out of 5 with the same assertion and the same relative line 56 as the CI job. At the failure PTTL on the key returns a live 297 ms, which is the direct evidence that the server expires correctly and only the test's deadline arithmetic is wrong. Test-only fix in madolson/valkey-agents#59.

    This was generated by AI but verified, with love, by a human.

  3. madolson commented on Oct 27, 2026

    @madolson
    OwnerAuthor

    Fixed upstream by valkey-io/valkey#4673.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions