]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MEDIUM: clock: make sure now_ms cannot be TICK_ETERNITY
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Nov 2024 14:52:17 +0000 (15:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Nov 2024 15:01:31 +0000 (16:01 +0100)
commit5a3735a155d47786c20774a1492f3ed20cfe4df3
treea751f3b4a5b860fbbb54ef0eeaee711c30af4a17
parented55ff878d5af35dae70f78023ab2141d36e5866
BUG/MEDIUM: clock: make sure now_ms cannot be TICK_ETERNITY

In clock ticks, 0 is TICK_ETERNITY. Long ago we used to make sure now_ms
couldn't be zero so that it could be assigned to expiration timers, but
it has long changed after functions like tick_add() were instrumented to
make the check. The problem is that aside the rare few accidental direct
assignments to expiration dates, it's also used to mark the beginning of
an event that's later checked against TICK_ETERNITY to know if it has
already struck. The problem in this case is that certain events may just
be replaced or dropped just because they apparently never appeared. It's
probably the case for stconn's "lra" and "fsb" fields, just like it is
for all those involving tick_add_ifset(), like h2c->idle_start.

The right approach would be to change the type of now_ms to something
else that cannot take direct computations and that represents a timestamp,
forcing to always use the conversion functions. The variables holding such
timestamps would also be distinguished from intervals. At first glance we
could have for timestamps:
  - 0 = never happened (for the past), eternity (for the future)
  - X = date
and for intervals:
  - 0 = not set
  - X = interval

However this requires significant changes. Instead for now, let's just
make sure again that now_ms is never 0 by setting it to 1 when this
happens (1 / 4 billion times, or 1ms every 49.7 days).

This will need to be carefully backported to older versions. Note that
with this patch backported, the previous ones fixing the zero date are
not strictly needed.
src/clock.c