]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: time/threads: ensure the adjusted time is always correct
authorWilly Tarreau <w@1wt.eu>
Mon, 5 Feb 2018 19:11:38 +0000 (20:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 Feb 2018 19:11:38 +0000 (20:11 +0100)
commita331544c33d287471ba0afaad5de5289f3cc35ea
tree92e06ce122cbb6c3a8e794e56c6d30c19518c4e8
parent11559a7530931b7e58852e2ee2b576538e8f46fd
BUG/MINOR: time/threads: ensure the adjusted time is always correct

In the time offset calculation loop, we ensure we only commit the new
date once it's futher in the future than the current one. However there
is a small issue here on 32-bit platforms : if global_now is written in
two cycles by another thread, starting with the tv_sec part, and the
current thread reads it in the middle of a change, it may compute a
wrong "adjusted" value on the first round, with the new (larger) tv_sec
and the old (large) tv_usec. This will be detected as the CAS will fail,
and another attempt will be made, but this time possibly with too large
an adusted value, pushing the date further than needed (at worst almost
one second).

This patch addresses this by using a temporary adjusted time in the loop
that always restarts from the last known one, and by assigning the result
to the final value only once the CAS succeeds.

The impact is very limited, it may cause the time to advance in small
jumps on 32 bit platforms and in the worst case some timeouts might
expire 1 second too early.

This fix should be backported to 1.8.
src/time.c