spiegel_podman/libpod
Valentin Rothberg 30e7cbccc1 libpod: fix wait and exit-code logic
This commit addresses three intertwined bugs to fix an issue when using
Gitlab runner on Podman.  The three bug fixes are not split into
separate commits as tests won't pass otherwise; avoidable noise when
bisecting future issues.

1) Podman conflated states: even when asking to wait for the `exited`
   state, Podman returned as soon as a container transitioned to
   `stopped`.  The issues surfaced in Gitlab tests to fail [1] as
   `conmon`'s buffers have not (yet) been emptied when attaching to a
   container right after a wait.  The race window was extremely narrow,
   and I only managed to reproduce with the Gitlab runner [1] unit
   tests.

2) The clearer separation between `exited` and `stopped` revealed a race
   condition predating the changes.  If a container is configured for
   autoremoval (e.g., via `run --rm`), the "run" process competes with
   the "cleanup" process running in the background.  The window of the
   race condition was sufficiently large that the "cleanup" process has
   already removed the container and storage before the "run" process
   could read the exit code and hence waited indefinitely.

   Address the exit-code race condition by recording exit codes in the
   main libpod database.  Exit codes can now be read from a database.
   When waiting for a container to exit, Podman first waits for the
   container to transition to `exited` and will then query the database
   for its exit code. Outdated exit codes are pruned during cleanup
   (i.e., non-performance critical) and when refreshing the database
   after a reboot.  An exit code is considered outdated when it is older
   than 5 minutes.

   While the race condition predates this change, the waiting process
   has apparently always been fast enough in catching the exit code due
   to issue 1): `exited` and `stopped` were conflated.  The waiting
   process hence caught the exit code after the container transitioned
   to `stopped` but before it `exited` and got removed.

3) With 1) and 2), Podman is now waiting for a container to properly
   transition to the `exited` state.  Some tests did not pass after 1)
   and 2) which revealed the third bug: `conmon` was executed with its
   working directory pointing to the OCI runtime bundle of the
   container.  The changed working directory broke resolving relative
   paths in the "cleanup" process.  The "cleanup" process error'ed
   before actually cleaning up the container and waiting "main" process
   ran indefinitely - or until hitting a timeout.  Fix the issue by
   executing `conmon` with the same working directory as Podman.

Note that fixing 3) *may* address a number of issues we have seen in the
past where for *some* reason cleanup processes did not fire.

[1] https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27119#note_970712864

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>

[MH: Minor reword of commit message]

Signed-off-by: Matthew Heon <mheon@redhat.com>
2022-06-23 09:11:57 -04:00
..
common fix a number of godot issues 2022-03-22 13:04:35 +01:00
define libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
driver bump go module to version 4 2022-01-18 12:47:07 +01:00
events fix CI: golangci-lint is broken on main 2022-06-15 14:57:10 +02:00
layers Initial checkin from CRI-O repo 2017-11-01 11:24:59 -04:00
linkmode go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
lock golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
logs enable gocritic linter 2022-04-26 18:12:22 +02:00
plugin golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
shutdown Fix CI flake on time of shutdown for API service 2021-10-12 09:53:19 -07:00
boltdb_state.go libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
boltdb_state_internal.go libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
boltdb_state_linux.go go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
common_test.go bump go module to version 4 2022-01-18 12:47:07 +01:00
container.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
container_api.go libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
container_commit.go container-commit: support --squash to squash layers into one 2022-02-23 17:38:28 +05:30
container_config.go Merge pull request #14659 from eriksjolund/setup_to_set_up_in_code 2022-06-21 18:08:31 +00:00
container_copy_linux.go podman cp: do not overwrite non-dirs with dirs and vice versa 2022-06-10 09:42:19 +02:00
container_exec.go golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
container_graph.go bump go module to version 4 2022-01-18 12:47:07 +01:00
container_graph_test.go bump go module to version 4 2022-01-18 12:47:07 +01:00
container_inspect.go k8systemd: run k8s workloads in systemd 2022-05-17 10:18:58 +02:00
container_internal.go libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
container_internal_linux.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
container_internal_linux_test.go test: use T.TempDir to create temporary test directory 2022-05-05 21:09:41 +08:00
container_internal_test.go test: fix failing TestPostDeleteHooks 2022-05-05 21:39:46 +08:00
container_linux.go go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
container_log.go podman logs k8s-file: do not reassemble partial log lines 2022-06-03 15:01:23 +02:00
container_log_linux.go golangci-lint: add systemd build tag 2022-06-14 15:28:45 +02:00
container_log_unsupported.go Add option for pod logs to display different colors per container. 2022-03-29 17:29:13 +02:00
container_path_resolution.go document that using libpod package directly is not supported 2022-03-23 19:05:29 +01:00
container_stat_linux.go enable gocritic linter 2022-04-26 18:12:22 +02:00
container_top_linux.go contain_top_linux.go: s/TODO/NOTE/ 2022-05-24 13:40:02 +02:00
container_validate.go k8systemd: run k8s workloads in systemd 2022-05-17 10:18:58 +02:00
diff.go fix --init with /dev bind mount 2022-05-23 13:59:05 +02:00
doc.go document that using libpod package directly is not supported 2022-03-23 19:05:29 +01:00
events.go libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
healthcheck.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
healthcheck_linux.go healthcheck: wait for systemd operations 2022-05-27 13:10:35 +02:00
info.go Refactor populating uptime 2022-05-26 15:46:04 -07:00
info_test.go Robust whitespace split of cpu utilization line from /proc/stat 2022-05-14 00:34:56 +00:00
kube.go golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
mounts_linux.go go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
networking_linux.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
networking_linux_test.go enable unparam linter 2022-04-25 13:23:20 +02:00
networking_machine.go enable gocritic linter 2022-04-26 18:12:22 +02:00
networking_slirp4netns.go enable gocritic linter 2022-04-26 18:12:22 +02:00
oci.go Move Attach under the OCI Runtime interface 2022-05-26 14:57:08 -04:00
oci_conmon.go podman: add new cgroup mode split 2020-06-25 17:16:12 +02:00
oci_conmon_attach_linux.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
oci_conmon_exec_linux.go play kube log tag handling 2022-05-06 15:59:06 -04:00
oci_conmon_linux.go libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
oci_missing.go Move Attach under the OCI Runtime interface 2022-05-26 14:57:08 -04:00
oci_util.go bump go module to version 4 2022-01-18 12:47:07 +01:00
options.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
pod.go podman pod clone 2022-06-10 14:23:19 -04:00
pod_api.go patch for pod host networking & other host namespace handling 2022-06-09 10:30:48 -04:00
pod_internal.go bump go module to version 4 2022-01-18 12:47:07 +01:00
pod_status.go bump go module to version 4 2022-01-18 12:47:07 +01:00
pod_top_linux.go libpod/pod_top_linux.go: s/TODO/NOTE/ 2022-05-25 12:30:19 +02:00
reset.go Improve robustness of podman system reset 2022-06-03 12:54:08 -04:00
runtime.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
runtime_cstorage.go Remove the runtime lock 2022-02-22 11:05:26 -05:00
runtime_ctr.go Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
runtime_img.go play kube: service container 2022-05-12 10:51:13 +02:00
runtime_migrate.go enable unparam linter 2022-04-25 13:23:20 +02:00
runtime_pod.go Use containers/common/pkg/util.StringToSlice 2022-05-23 12:16:54 -04:00
runtime_pod_linux.go play kube: service container 2022-05-12 10:51:13 +02:00
runtime_renumber.go auto update: create an event 2022-05-23 14:11:29 +02:00
runtime_volume.go Remove the runtime lock 2022-02-22 11:05:26 -05:00
runtime_volume_linux.go volume: add new option -o o=noquota 2022-04-28 13:29:01 +02:00
runtime_worker.go work queue: simplify and use a wait group 2022-05-25 10:17:46 +02:00
service.go k8systemd: run k8s workloads in systemd 2022-05-17 10:18:58 +02:00
state.go libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
state_test.go bump go module to version 4 2022-01-18 12:47:07 +01:00
stats.go Non-running containers now report statistics via the podman stats 2022-06-13 15:03:22 -04:00
storage.go bump go module to version 4 2022-01-18 12:47:07 +01:00
util.go enable errcheck linter 2022-04-29 14:06:38 +02:00
util_linux.go go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
util_linux_test.go Fix mismatch between log messages and behavior of libpod.LabelVolumePath. 2020-09-13 23:24:15 -04:00
util_test.go bump go module to version 4 2022-01-18 12:47:07 +01:00
volume.go volume: add new option -o o=noquota 2022-04-28 13:29:01 +02:00
volume_inspect.go bump go module to version 4 2022-01-18 12:47:07 +01:00
volume_internal.go volume: add new option -o o=noquota 2022-04-28 13:29:01 +02:00
volume_internal_linux.go Add podman volume mount support 2022-02-28 14:26:22 -05:00