Browse Source

[core] adjust time jump detection (fixes #3123)

adjust time jump detection to handle when server.max-workers is non-zero

x-ref:
  "child exit causes time jump false positive when server.max-workers is non-zero"
  https://redmine.lighttpd.net/issues/3123
master
Glenn Strauss 6 months ago
parent
commit
b68b805c54
  1. 22
      src/server.c

22
src/server.c

@ -247,18 +247,21 @@ server_monotonic_secs (void)
}
static unix_time64_t
server_epoch_secs (server * const srv)
server_epoch_secs (server * const srv, unix_time64_t mono_ts_delta)
{
const unix_time64_t cur_ts = log_epoch_secs;
const unix_time64_t new_ts = TIME64_CAST(time(NULL));
const unix_time64_t new_ts_adj = new_ts - mono_ts_delta;
/* attempt to detect large clock jump */
if (new_ts < cur_ts || new_ts - cur_ts > 300) { /*(5 mins)*/
if (new_ts_adj < cur_ts || new_ts_adj - cur_ts > 300) { /*(5 mins)*/
log_error(srv->errh, __FILE__, __LINE__,
"warning: clock jumped %lld secs",
(long long)((int64_t)new_ts - (int64_t)cur_ts));
(long long)((int64_t)new_ts_adj - (int64_t)cur_ts));
int delta = /*(30 mins default)*/
config_feature_int(srv, "server.clock-jump-restart", 1800);
if (delta && (new_ts > cur_ts ? new_ts-cur_ts : cur_ts-new_ts) > delta){
if (delta && (new_ts_adj > cur_ts
? new_ts_adj-cur_ts
: cur_ts-new_ts_adj) > delta) {
log_error(srv->errh, __FILE__, __LINE__,
"attempting graceful restart in < ~5 seconds, else hard restart");
srv->graceful_expire_ts = log_monotonic_secs + 5;
@ -1613,10 +1616,12 @@ static int server_main_setup (server * const srv, int argc, char **argv) {
}
} else {
int status;
unix_time64_t mono_ts;
if (-1 != (pid = fdevent_waitpid_intr(-1, &status))) {
mono_ts = log_monotonic_secs;
log_monotonic_secs = server_monotonic_secs();
log_epoch_secs = server_epoch_secs(srv);
log_epoch_secs = server_epoch_secs(srv, log_monotonic_secs - mono_ts);
if (plugins_call_handle_waitpid(srv, pid, status) != HANDLER_GO_ON) {
if (!timer) alarm((timer = 5));
continue;
@ -1640,8 +1645,9 @@ static int server_main_setup (server * const srv, int argc, char **argv) {
} else {
switch (errno) {
case EINTR:
mono_ts = log_monotonic_secs;
log_monotonic_secs = server_monotonic_secs();
log_epoch_secs = server_epoch_secs(srv);
log_epoch_secs = server_epoch_secs(srv, log_monotonic_secs - mono_ts);
/**
* if we receive a SIGHUP we have to close our logs ourself as we don't
* have the mainloop who can help us here
@ -1840,7 +1846,7 @@ static void server_handle_sigalrm (server * const srv, unix_time64_t mono_ts, un
plugins_call_handle_trigger(srv);
log_monotonic_secs = mono_ts;
log_epoch_secs = server_epoch_secs(srv);
log_epoch_secs = server_epoch_secs(srv, 0);
/* check idle time limit, if enabled */
if (idle_limit && idle_limit < mono_ts - last_active_ts && !graceful_shutdown) {
@ -1923,7 +1929,7 @@ __attribute_hot__
__attribute_noinline__
static void server_main_loop (server * const srv) {
unix_time64_t last_active_ts = server_monotonic_secs();
log_epoch_secs = server_epoch_secs(srv);
log_epoch_secs = server_epoch_secs(srv, 0);
while (!srv_shutdown) {

Loading…
Cancel
Save