Skip to content

Commit

Permalink
Merge pull request #5183 from giuseppe/rootlessport-avoid-hang
Browse files Browse the repository at this point in the history
rootlessport: fix potential hang
  • Loading branch information
openshift-merge-robot authored Feb 13, 2020
2 parents c16e12f + 5b69e7f commit 5ea6cad
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pkg/rootlessport/rootlessport_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func parent() error {
logrus.WithError(driverErr).Warn("parent driver exited")
}
errCh <- driverErr
close(errCh)
}()
opaque := driver.OpaqueForChild()
logrus.Infof("opaque=%+v", opaque)
Expand All @@ -142,15 +143,12 @@ func parent() error {
}()

// reexec the child process in the child netns
cmd := exec.Command(fmt.Sprintf("/proc/%d/exe", os.Getpid()))
cmd := exec.Command("/proc/self/exe")
cmd.Args = []string{reexecChildKey}
cmd.Stdin = childQuitR
cmd.Stdout = &logrusWriter{prefix: "child"}
cmd.Stderr = cmd.Stdout
cmd.Env = append(os.Environ(), reexecChildEnvOpaque+"="+string(opaqueJSON))
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGTERM,
}
childNS, err := ns.GetNS(cfg.NetNSPath)
if err != nil {
return err
Expand All @@ -162,14 +160,27 @@ func parent() error {
return err
}

defer func() {
if err := syscall.Kill(cmd.Process.Pid, syscall.SIGTERM); err != nil {
logrus.WithError(err).Warn("kill child process")
}
}()

logrus.Info("waiting for initComplete")
// wait for the child to connect to the parent
select {
case <-initComplete:
logrus.Infof("initComplete is closed; parent and child established the communication channel")
case err := <-errCh:
return err
outer:
for {
select {
case <-initComplete:
logrus.Infof("initComplete is closed; parent and child established the communication channel")
break outer
case err := <-errCh:
if err != nil {
return err
}
}
}

defer func() {
logrus.Info("stopping parent driver")
quit <- struct{}{}
Expand Down

0 comments on commit 5ea6cad

Please sign in to comment.