summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-10-31 06:28:24 -0700
committerGitHub <noreply@github.com>2018-10-31 06:28:24 -0700
commitcf4288e3cc1cd95e512cae063066ca26917e378e (patch)
tree8157563017e5120afec08d554d74812d538c640d
parentee513cca8612bebfda36e31203ab215aa682e8c0 (diff)
parentea50ce6a5915f71e0cf355d2006ad035adf37034 (diff)
downloadpodman-cf4288e3cc1cd95e512cae063066ca26917e378e.tar.gz
podman-cf4288e3cc1cd95e512cae063066ca26917e378e.tar.bz2
podman-cf4288e3cc1cd95e512cae063066ca26917e378e.zip
Merge pull request #1735 from giuseppe/slirp4netns-not-block
rootless: avoid hang on failed slirp4netns
-rw-r--r--libpod/networking_linux.go28
1 files changed, 25 insertions, 3 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 0d9ec2809..863a764e2 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -12,6 +12,7 @@ import (
"strconv"
"strings"
"syscall"
+ "time"
cnitypes "github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/plugins/pkg/ns"
@@ -134,12 +135,33 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
cmd.ExtraFiles = append(cmd.ExtraFiles, ctr.rootlessSlirpSyncR, syncW)
if err := cmd.Start(); err != nil {
- return errors.Wrapf(err, "failed to start process")
+ return errors.Wrapf(err, "failed to start slirp4netns process")
}
+ defer cmd.Process.Release()
b := make([]byte, 16)
- if _, err := syncR.Read(b); err != nil {
- return errors.Wrapf(err, "failed to read from sync pipe")
+ for {
+ if err := syncR.SetDeadline(time.Now().Add(1 * time.Second)); err != nil {
+ return errors.Wrapf(err, "error setting slirp4netns pipe timeout")
+ }
+ if _, err := syncR.Read(b); err == nil {
+ break
+ } else {
+ if os.IsTimeout(err) {
+ // Check if the process is still running.
+ var status syscall.WaitStatus
+ _, err := syscall.Wait4(cmd.Process.Pid, &status, syscall.WNOHANG, nil)
+ if err != nil {
+ return errors.Wrapf(err, "failed to read slirp4netns process status")
+ }
+ if status.Exited() || status.Signaled() {
+ return errors.New("slirp4netns failed")
+ }
+
+ continue
+ }
+ return errors.Wrapf(err, "failed to read from slirp4netns sync pipe")
+ }
}
return nil
}