sd-event: use CLOCK_BOOTTIME for rate limits
When a rate limit is armed, for example via StartLimitInterval=, and the machine is suspended, the rate limit's "clock" is suspended as well, since the elapse checks use CLOCK_MONOTONIC. This then causes unexpected situations where a rate limit armed via StartLimitInterval=1h, followed by a 10 hour suspend, would elapse after 11 hours total. Let's avoid this by switching the rate limits to CLOCK_BOOTTIME, which works the same as CLOCK_MONOTONIC, but accounts for the time spent in suspend as well. There's one slight concern when it comes to upgrade path - the old "begin" value of the rate limit is stored as CLOCK_MONOTONIC, but after upgrading systemd and serializing/deserializing the state it will be suddenly compared against now(CLOCK_BOOTTIME), which might cause some rate limits to elapse "prematurely". But this is just a one-time thing, after which the rate limit timers should re-assess themselves. Resolves: #42912
This commit is contained in:
committed by
Luca Boccassi
parent
0168b13fb3
commit
9ae50c78cc
+1
-1
@@ -1517,7 +1517,7 @@ static int manager_ratelimit_check_and_queue(Unit *u) {
|
||||
r = sd_event_add_time(
|
||||
u->manager->event,
|
||||
&u->auto_start_stop_event_source,
|
||||
CLOCK_MONOTONIC,
|
||||
CLOCK_BOOTTIME,
|
||||
ratelimit_end(&u->auto_start_stop_ratelimit),
|
||||
0,
|
||||
manager_ratelimit_requeue,
|
||||
|
||||
Reference in New Issue
Block a user