summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-05-14 16:31:55 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-05-14 16:56:02 -0400
commit0f0abe290927cd17542953042885b554dbffd83e (patch)
tree202857ba4b7586744a194fecb73af65b8380f466
parent0c3bed119b16e90534172410f70713591ecafc4c (diff)
downloadpodman-0f0abe290927cd17542953042885b554dbffd83e.tar.gz
podman-0f0abe290927cd17542953042885b554dbffd83e.tar.bz2
podman-0f0abe290927cd17542953042885b554dbffd83e.zip
Prune stale exec sessions on inspect
The usual flow for exec is going to be: - Create exec session - Start and attach to exec session - Exec session exits, attach session terminates - Client does an exec inspect to pick up exit code The safest point to remove the exec session, without doing any database changes to track stale sessions, is to remove during the last part of this - the single inspect after the exec session exits. This is definitely different from Docker (which would retain the exec session for up to 10 minutes after it exits, where we will immediately discard) but should be close enough to be not noticeable in regular usage. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
-rw-r--r--libpod/container_exec.go2
-rw-r--r--pkg/api/handlers/compat/exec.go9
2 files changed, 10 insertions, 1 deletions
diff --git a/libpod/container_exec.go b/libpod/container_exec.go
index 979594eb4..6ad767b4b 100644
--- a/libpod/container_exec.go
+++ b/libpod/container_exec.go
@@ -104,7 +104,7 @@ func (e *ExecSession) Inspect() (*define.InspectExecSession, error) {
}
output := new(define.InspectExecSession)
- output.CanRemove = e.State != define.ExecStateRunning
+ output.CanRemove = e.State == define.ExecStateStopped
output.ContainerID = e.ContainerId
if e.Config.DetachKeys != nil {
output.DetachKeys = *e.Config.DetachKeys
diff --git a/pkg/api/handlers/compat/exec.go b/pkg/api/handlers/compat/exec.go
index df4950947..f97fecca2 100644
--- a/pkg/api/handlers/compat/exec.go
+++ b/pkg/api/handlers/compat/exec.go
@@ -106,6 +106,15 @@ func ExecInspectHandler(w http.ResponseWriter, r *http.Request) {
}
utils.WriteResponse(w, http.StatusOK, inspectOut)
+
+ // Only for the Compat API: we want to remove sessions that were
+ // stopped. This is very hacky, but should suffice for now.
+ if !utils.IsLibpodRequest(r) && inspectOut.CanRemove {
+ logrus.Infof("Pruning stale exec session %s from container %s", sessionID, sessionCtr.ID())
+ if err := sessionCtr.ExecRemove(sessionID, false); err != nil && errors.Cause(err) != define.ErrNoSuchExecSession {
+ logrus.Errorf("Error removing stale exec session %s from container %s: %v", sessionID, sessionCtr.ID(), err)
+ }
+ }
}
// ExecResizeHandler resizes a given exec session's TTY.