]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MEDIUM: threads/time: fix time drift correction
authorWilly Tarreau <w@1wt.eu>
Thu, 23 Nov 2017 10:52:55 +0000 (11:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 23 Nov 2017 15:32:32 +0000 (16:32 +0100)
commit7649aacf7f17410b88f258b2b2eddea9e8445922
tree8dc23b187954ec189b7f875fc531f4ad091c9904
parent158fa7581173234ab3bebf9dee91d18cf6a138d0
BUG/MEDIUM: threads/time: fix time drift correction

With threads, it became mandatory to implement a thread-local time with
its own correction. However, it was noticed that during high thread
contention, the time correction could occasionally be wrong, reporting
huge negative or positive timers in logs. This was caused by the
conversion between struct timeval and a single 64-bit offset, due to
an erroneous shift and due to a loss of sign during the conversion.

Given that time_t is not always signed, and that timeval is not really
needed here, better avoid playing dangerous games with these operations
and use a single 64-bit offset representing a signed 32-bit offset, for
the seconds part and an unsigned offset for the microsecond part.
It still supports atomic updates and doesn't cause issues anymore.
src/time.c