-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rootlessport: fix potential hang #5183
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what was the problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the child process is killed whenever the parent thread exits which we have no control about since it is managed by the Go runtime. |
||
childNS, err := ns.GetNS(cfg.NetNSPath) | ||
if err != nil { | ||
return err | ||
|
@@ -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{}{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe close errCh?