spiegel_podman/pkg
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
..
annotations fix a number of godot issues 2022-03-22 13:04:35 +01:00
api libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
auth pkg/auth: drop the TODO 2022-05-25 12:33:34 +02:00
autoupdate auto update: create an event 2022-05-23 14:11:29 +02:00
bindings Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
channel channel: simplify implementation 2021-05-06 11:51:15 +02:00
checkpoint Add support for checkpoint image 2022-04-20 18:55:39 +01:00
copy bump go module to version 4 2022-01-18 12:47:07 +01:00
criu Add support for checkpoint image 2022-04-20 18:55:39 +01:00
ctime golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
domain libpod: fix wait and exit-code logic 2022-06-23 09:11:57 -04:00
env Add more unit tests 2022-05-04 08:29:54 -05:00
errorhandling golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
hooks golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
inspect pkg/inspect: remove unused ImageResult type 2022-05-24 16:07:39 +02:00
k8s.io golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00
kubeutils remove unneeded k8s code 2022-03-15 14:48:08 +01:00
lookup enable gocritic linter 2022-04-26 18:12:22 +02:00
machine Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
namespaces Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
parallel bump go module to version 4 2022-01-18 12:47:07 +01:00
ps bump go module to version 4 2022-01-18 12:47:07 +01:00
rootless Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
rootlessport go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
seccomp Spelling 2020-12-22 13:34:31 -05:00
selinux Fix SELinux functions names to not be repetitive 2020-04-23 15:57:34 -04:00
servicereaper go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
signal cmd/podman/common/completion.go: fix FIXMEs 2022-05-24 17:56:37 +02:00
specgen podman pod create --shm-size 2022-06-20 10:25:00 -04:00
specgenutil podman pod clone 2022-06-10 14:23:19 -04:00
systemd Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
terminal move golang.org/x/crypto/ssh/terminal to golang.org/x/term 2022-04-22 12:40:52 +02:00
timetype enable gocritic linter 2022-04-26 18:12:22 +02:00
trust Cleanup display of trust with transports 2022-02-22 15:08:58 -05:00
util golangci-lint: enable nolintlint 2022-06-14 16:29:42 +02:00