Skip to content

Commit

Permalink
Sync: handle exit file
Browse files Browse the repository at this point in the history
Make sure `Sync()` handles state transitions and exit codes correctly.
The function was only being called when batching which could render
containers in an unusable state when running concurrently with other
state-altering functions/commands since the state must be re-read from
the database before acting upon it.

Fixes: containers#14761
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Jul 5, 2022
1 parent 773eead commit b9aa475
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 2 additions & 13 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,19 +761,8 @@ func (c *Container) Sync() error {
defer c.lock.Unlock()
}

// If runtime knows about the container, update its status in runtime
// And then save back to disk
if c.ensureState(define.ContainerStateCreated, define.ContainerStateRunning, define.ContainerStatePaused, define.ContainerStateStopped, define.ContainerStateStopping) {
oldState := c.state.State
if err := c.ociRuntime.UpdateContainerStatus(c); err != nil {
return err
}
// Only save back to DB if state changed
if c.state.State != oldState {
if err := c.save(); err != nil {
return err
}
}
if err := c.syncContainer(); err != nil {
return err
}

defer c.newContainerEvent(events.Sync)
Expand Down
10 changes: 10 additions & 0 deletions test/system/130-kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,14 @@ load helpers
is "$output" $cname
}

@test "podman kill - concurrent stop" {
# 14761 - concurrent kill/stop must record the exit code
random_name=$(random_string 10)
run_podman run -d --replace --name=$random_name alpine sh -c "trap 'echo Received SIGTERM, ignoring' SIGTERM; echo READY; while :; do sleep 0.2; done"
$PODMAN stop -t 1 $random_name &
run_podman kill $random_name
run_podman wait $random_name
run_podman rm -f $random_name
}

# vim: filetype=sh

0 comments on commit b9aa475

Please sign in to comment.