From bba286036e3d470aba293f948c7056341fdbf3aa Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 19 Nov 2026 18:49:44 +0100 Subject: [PATCH] service: save the configured restart delay when registering The configured restart delay was saved at the first restart, when the restart counter went from zero to one, and restored when a restart succeeded. The counter ages back to zero while the service runs. If it did so right after a restart and the service crashed again, the back-off delay was saved over the configured one. From then on the first restart after a crash waited two or five seconds, until the next reload. Save it once, when the service is registered. Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 2 ++ src/service.c | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index d6f363c5..a4eac5c0 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -188,6 +188,8 @@ All relevant changes are documented in this file. - Fix a command whose name starts like a service option, e.g. `logger` or `pidof`. It was taken as the `log` or `pid` option and the next argument ran as the command, which also broke the `logger` example in finit.conf(5) +- Fix the delay before the first restart of a crashing service, it could + grow to the back-off delay and stay there until the next reload - Fix the restart counter of a service with `restart = "always"`, nothing stopped it and it overflowed after 127 restarts, 255 on Arm. It now stops at 10, where the back-off has long since peaked, and ages from diff --git a/src/service.c b/src/service.c index 36f6fb4b..3545a556 100644 --- a/src/service.c +++ b/src/service.c @@ -2776,6 +2776,7 @@ svc_t *service_register_desc(int type, char *cfg, const char *desc, /* TTYs need a longer default to throttle errors (e.g., missing device) */ if (svc_is_tty(svc) && svc->restart_tmo == 0) svc->restart_tmo = 2000; + svc->restart_saved = svc->restart_tmo; /* Set configured limits */ memcpy(svc->rlimit, rlimit, sizeof(svc->rlimit)); @@ -3334,8 +3335,6 @@ static void service_retry(svc_t *svc) restart_cnt_inc(svc); dbg("%s crashed, trying to start it again, attempt %d", svc_ident(svc, NULL, 0), *restart_cnt); - if ((*restart_cnt) == 1) - svc->restart_saved = svc->restart_tmo; /* Wait 2s for the first half of the attempts, then back off to 5s */ half = (svc->restart_max == -1 ? SVC_RESPAWN_MAX : svc->restart_max) / 2; timeout = *restart_cnt <= half ? 2000 : 5000;