Project

General

Profile

patch: use monotonic clock for time-outs

Added by volkere almost 9 years ago

hi,

wall clock time is not a good base to detect time-outs because it might jump around quite freely. for example consider a system without a battery-backed clock, which will jump from unix 0 (1970) to 40 years later when the clock is set, possibly much later.

using the monotonic clock should be the way to go and indeed it works much better (no more time-outs, regardless of how much the wall clock jumps around).

this was only tested on linux and should apply to the 1.4.x branch.

signed-off-by: volker.eckert<TA>gmx.net


Replies (2)

RE: patch: use monotonic clock for time-outs - Added by darix almost 9 years ago

should have a configure check if we need -lrt for clock_gettime. what about BSDs?

also putting it into a bug would be better.

RE: patch: use monotonic clock for time-outs - Added by gstrauss over 7 years ago

lighttpd support for clock_gettime() (and workaround for MacOSX) was added in lighttpd 1.4.40.

However, the patch submitted can not be used as-is because srv->cur_ts is used for both "Date" response header generation, as well as for relative times.

If "non-linear" time is a problem more than twice a year (for daylight savings time), then perhaps lighttpd could detect if time moves backwards >= 1 second. More than a few places in lighttpd use srv->cur_ts for time, and so each would have to be reviewed and changed to properly use realtime or monotonic time explicitly. (If using realtime, then each use should review whether or not to detect clock moving backwards.)

    (1-2/2)