Skip to content

Commit

Permalink
remote: exec inspect update exec session status
Browse files Browse the repository at this point in the history
The remote API will wait 300s by default before conmon will call the
cleanup. In the meantime when you inspect an exec session started with
ExecStart() (so not attached) and it did exit we do not know that. If
a caller inspects it they think it is still running. To prevent this we
should sync the session based on the exec pid and update the state
accordingly.

For a reproducer see the test in this commit or the issue.

Fixes containers#18424

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed May 23, 2023
1 parent 5b21c38 commit 66fb7c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,17 @@ func (c *Container) execSessionNoCopy(id string) (*ExecSession, error) {
return nil, fmt.Errorf("no exec session with ID %s found in container %s: %w", id, c.ID(), define.ErrNoSuchExecSession)
}

// make sure to update the exec session if needed #18424
alive, err := c.ociRuntime.ExecUpdateStatus(c, id)
if err != nil {
return nil, err
}
if !alive {
if err := retrieveAndWriteExecExitCode(c, session.ID()); err != nil {
return nil, err
}
}

return session, nil
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/bindings/test/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("Podman containers exec", func() {
bt.cleanup()
})

It("Podman exec create makes an exec session", func() {
It("Podman exec create+start makes an exec session", func() {
name := "testCtr"
cid, err := bt.RunTopContainer(&name, nil)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -48,6 +48,15 @@ var _ = Describe("Podman containers exec", func() {
Expect(inspectOut.ProcessConfig.Entrypoint).To(Equal("echo"))
Expect(inspectOut.ProcessConfig.Arguments).To(HaveLen(1))
Expect(inspectOut.ProcessConfig.Arguments[0]).To(Equal("hello world"))

err = containers.ExecStart(bt.conn, sessionID, nil)
Expect(err).ToNot(HaveOccurred())

inspectOut, err = containers.ExecInspect(bt.conn, sessionID, nil)
Expect(err).ToNot(HaveOccurred())
Expect(inspectOut.ContainerID).To(Equal(cid))
Expect(inspectOut.Running).To(BeFalse(), "session should not be running")
Expect(inspectOut.ExitCode).To(Equal(0), "exit code from echo")
})

It("Podman exec create with bad command fails", func() {
Expand Down

0 comments on commit 66fb7c9

Please sign in to comment.