Skip to content

conmon: do not fire --timeout early - #708

Merged
kolyshkin merged 1 commit into
containers:mainfrom
kolyshkin:kir/timeout-precise
Oct 26, 2026
Merged

kolyshkin merged 1 commit into
containers:mainfrom
kolyshkin:kir/timeout-precise

Conversation

@kolyshkin

Copy link
Copy Markdown
Collaborator

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 (see g_timeout_set_expiration in glib's gmain.c).

As a result, podman run --timeout 2 IMAGE sleep 60 sometimes takes less than 2 seconds in total, and podman's podman run --timeout - basic test system test flakes with:

FAIL: podman stop: ran too quickly!
expected: -gt 1
  actual:     1

(seen in runc CI: https://github.com/opencontainers/runc/actions/runs/40177692604/job/121122129191, where the whole podman run took 1.92s).

Use g_timeout_add with milliseconds instead, which does not round. Keep g_timeout_add_seconds for timeouts that do not fit into guint milliseconds (about 49 days), as the imprecision does not matter there.

Measured locally (rootless podman 5.8.9, 12 runs of podman run --rm --timeout 2 ... sleep 60, container setup takes ~100ms):

conmon total time, ms
2.2.1 1976–2019
this PR 2103–2123

@jnovy jnovy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice fix.

The overflow guard (guint)opt_timeout <= G_MAXUINT / 1000 is correct - max product is 4294967000 which fits in guint. The (guint) cast is safe because the outer opt_timeout > 0 check guarantees a positive value (opt_timeout is int per cli.c:42). Fallback to g_timeout_add_seconds() for >49-day timeouts is a sensible choice since 250ms imprecision is irrelevant at that scale.

Builds clean with -Werror locally, no warnings.

One note: the PR branch needs a rebase onto current main - the diff includes stale GitHub Actions version pins from before renovate PRs #700, #701, #704 merged. Without rebase, merging would revert those updates.

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 <kolyshkin@gmail.com>
@kolyshkin
kolyshkin force-pushed the kir/timeout-precise branch from d717898 to 7f06cc8 Compare October 26, 2026 09:24
@kolyshkin
kolyshkin merged commit ae6c3fd into containers:main Oct 26, 2026
14 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants