From 7f06cc85484dea25ffa441f1776b0b6be8cbaa24 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 25 Oct 2026 02:43:57 -0700 Subject: [PATCH] conmon: do not fire --timeout early The --timeout timer is set with g_timeout_add_seconds, which rounds the expiration time to a whole second boundary (adjusted by a per-host offset) to group wakeups. When the sub-second remainder is less than 250ms it is rounded down, so the timer can fire up to 250ms before the requested timeout. As a result, "podman run --timeout 2 IMAGE sleep 60" sometimes takes less than 2 seconds in total (as measured locally, 1976-2019ms over 12 runs, with about 100ms spent on container setup), and podman's "podman run --timeout - basic test" system test flakes with: FAIL: podman stop: ran too quickly! expected: -gt 1 actual: 1 Use g_timeout_add with milliseconds instead, which does not round. With this change, the same command takes 2103-2123ms. Keep g_timeout_add_seconds for timeouts that do not fit into guint milliseconds (about 49 days), as the imprecision does not matter there. Signed-off-by: Kir Kolyshkin --- src/conmon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/conmon.c b/src/conmon.c index b47a7b7e..8f3f468f 100644 --- a/src/conmon.c +++ b/src/conmon.c @@ -439,7 +439,14 @@ int main(int argc, char *argv[]) } if (opt_timeout > 0) { - g_timeout_add_seconds(opt_timeout, timeout_cb, NULL); + /* + * Do not use g_timeout_add_seconds here: it rounds the expiration + * to a whole second boundary, and may fire up to 250ms early. + */ + if ((guint)opt_timeout <= G_MAXUINT / 1000) + g_timeout_add((guint)opt_timeout * 1000, timeout_cb, NULL); + else /* Too long for g_timeout_add, imprecision does not matter. */ + g_timeout_add_seconds(opt_timeout, timeout_cb, NULL); } if (data.exit_status_cache) {