diff options
| author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-01-25 10:09:43 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-25 10:09:43 -0500 |
| commit | 92635c726ac063770f20ce9cc3da48f33a5ad73b (patch) | |
| tree | e6be6f4dc40de3d627b07824309b2b857ceb30c3 /libpod/container_exec.go | |
| parent | 534c4881b51b1bffaac1afcfbcfdc0dde09ccdb4 (diff) | |
| parent | e252b3b4f294745ca8ac6d1c1850de2e7f1365c7 (diff) | |
| download | podman-92635c726ac063770f20ce9cc3da48f33a5ad73b.tar.gz podman-92635c726ac063770f20ce9cc3da48f33a5ad73b.tar.bz2 podman-92635c726ac063770f20ce9cc3da48f33a5ad73b.zip | |
Merge pull request #12857 from giuseppe/fix-rm-dir-not-empty
exec: retry rm -rf on ENOTEMPTY and EBUSY
Diffstat (limited to 'libpod/container_exec.go')
| -rw-r--r-- | libpod/container_exec.go | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/libpod/container_exec.go b/libpod/container_exec.go index 7d4e28d5d..d1c190905 100644 --- a/libpod/container_exec.go +++ b/libpod/container_exec.go @@ -14,6 +14,7 @@ import ( "github.com/containers/storage/pkg/stringid" "github.com/pkg/errors" "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" ) // ExecConfig contains the configuration of an exec session @@ -774,13 +775,40 @@ func (c *Container) Exec(config *ExecConfig, streams *define.AttachStreams, resi return exitCode, nil } -// cleanup an exec session after its done -func (c *Container) cleanupExecBundle(sessionID string) error { - if err := os.RemoveAll(c.execBundlePath(sessionID)); err != nil && !os.IsNotExist(err) { - return err +// cleanupExecBundle cleanups an exec session after its done +// Please be careful when using this function since it might temporarily unlock +// the container when os.RemoveAll($bundlePath) fails with ENOTEMPTY or EBUSY +// errors. +func (c *Container) cleanupExecBundle(sessionID string) (Err error) { + path := c.execBundlePath(sessionID) + for attempts := 0; attempts < 50; attempts++ { + Err = os.RemoveAll(path) + if Err == nil || os.IsNotExist(Err) { + return nil + } + if pathErr, ok := Err.(*os.PathError); ok { + Err = pathErr.Err + if errors.Cause(Err) == unix.ENOTEMPTY || errors.Cause(Err) == unix.EBUSY { + // give other processes a chance to use the container + if !c.batched { + if err := c.save(); err != nil { + return err + } + c.lock.Unlock() + } + time.Sleep(time.Millisecond * 100) + if !c.batched { + c.lock.Lock() + if err := c.syncContainer(); err != nil { + return err + } + } + continue + } + } + return } - - return nil + return } // the path to a containers exec session bundle |
