Skip to content
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

bugfix: containerd instance exit may cause container exit #1407

Merged
merged 1 commit into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ctrd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ func (c *Client) Cleanup() error {
return err
}

// Note(ziren): notify containerd is dead before containerd
// is really dead
c.watch.setContainerdDead(true)

// Ask the daemon to quit
syscall.Kill(c.daemonPid, syscall.SIGTERM)

Expand Down
30 changes: 27 additions & 3 deletions ctrd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,26 @@ func (m *Message) ExitTime() time.Time {

type watch struct {
sync.Mutex
//client *containerd.Client
containers map[string]*containerPack
hooks []func(string, *Message) error

// containerdDead to specify whether containerd process is dead
containerdDead bool
}

func (w *watch) setContainerdDead(isDead bool) error {
w.Lock()
defer w.Unlock()

w.containerdDead = isDead
return nil
}

func (w *watch) isContainerdDead() bool {
w.Lock()
defer w.Unlock()

return w.containerdDead
}

func (w *watch) add(pack *containerPack) {
Expand All @@ -49,9 +66,16 @@ func (w *watch) add(pack *containerPack) {

w.containers[pack.id] = pack

go func(pack *containerPack) {
go func(w *watch, pack *containerPack) {
status := <-pack.sch

// if containerd is dead, the task.Wait channel return is not because
// container' task quit, but the channel has broken.
// so we just return.
if w.isContainerdDead() {
return
}

logrus.Infof("the task has quit, id: %s, err: %v, exitcode: %d, time: %v",
pack.id, status.Error(), status.ExitCode(), status.ExitTime())

Expand Down Expand Up @@ -85,7 +109,7 @@ func (w *watch) add(pack *containerPack) {

pack.ch <- msg

}(pack)
}(w, pack)

logrus.Infof("success to add container, id: %s", pack.id)
}
Expand Down