mirror of https://github.com/containers/podman.git
libpod API: make wait endpoint better against rm races
In the common scenario of podman-remote run --rm the API is required to attach + start + wait to get exit code. This has the problem that the wait call races against the container removal from the cleanup process so it may not get the exit code back. However we keep the exit code around for longer than the container so we can just look it up in the endpoint. Of course this only works when we get a full id as param but podman-remote will do that. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
3215d5124f
commit
b3829a2932
|
@ -1393,3 +1393,7 @@ func (r *Runtime) SystemCheck(ctx context.Context, options entities.SystemCheckO
|
|||
|
||||
return report, err
|
||||
}
|
||||
|
||||
func (r *Runtime) GetContainerExitCode(id string) (int32, error) {
|
||||
return r.state.GetContainerExitCode(id)
|
||||
}
|
||||
|
|
|
@ -130,6 +130,17 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) {
|
|||
reports, err := containerEngine.ContainerWait(r.Context(), []string{name}, opts)
|
||||
if err != nil {
|
||||
if errors.Is(err, define.ErrNoSuchCtr) {
|
||||
// Special case: In the common scenario of podman-remote run --rm
|
||||
// the API is required to attach + start + wait to get exit code.
|
||||
// This has the problem that the wait call races against the container
|
||||
// removal from the cleanup process so it may not get the exit code back.
|
||||
// However we keep the exit code around for longer than the container so
|
||||
// we can just look it up here. Of course this only works when we get a
|
||||
// full id as param but podman-remote will do that
|
||||
if code, err := runtime.GetContainerExitCode(name); err == nil {
|
||||
WriteResponse(w, http.StatusOK, strconv.Itoa(int(code)))
|
||||
return
|
||||
}
|
||||
ContainerNotFound(w, name, err)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue