Skip to content

Commit

Permalink
protect containerd thread
Browse files Browse the repository at this point in the history
Signed-off-by: zhuangqh <zhuangqhc@gmail.com>
  • Loading branch information
zhuangqh authored and fuweid committed May 5, 2019
1 parent 7ce509a commit 5008d8d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions ctrd/supervisord/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -238,16 +239,26 @@ func (d *Daemon) runContainerd() error {
}
}

if err := cmd.Start(); err != nil {
return err
}

// reap the containerd process when it has been killed
pidChan := make(chan int)
// run and wait the containerd process
go func() {
cmd.Wait()
runtime.LockOSThread()
if err := cmd.Start(); err != nil {
logrus.Errorf("containerd failed to start: %v", err)
pidChan <- -1
return
}
pidChan <- cmd.Process.Pid
if err := cmd.Wait(); err != nil {
logrus.Errorf("containerd exits: %v", err)
}
}()

if err := d.setContainerdPid(cmd.Process.Pid); err != nil {
pid = <-pidChan
if pid == -1 {
return fmt.Errorf("containerd failed to start")
}
if err := d.setContainerdPid(pid); err != nil {
utils.KillProcess(d.pid)
return fmt.Errorf("failed to save the pid into %s: %v", d.pidPath(), err)
}
Expand Down

0 comments on commit 5008d8d

Please sign in to comment.