Fix shim deadlock when joining an existing pid namespace (#290)

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickaël Laventure 2016-07-15 11:49:43 -07:00 committed by Michael Crosby
parent 3abb9fc411
commit 0ac3cd1be1
6 changed files with 21 additions and 8 deletions

View file

@ -115,6 +115,7 @@ func start(log *os.File) error {
// runtime has exited so the shim can also exit // runtime has exited so the shim can also exit
if exitShim { if exitShim {
// Let containerd take care of calling the runtime delete // Let containerd take care of calling the runtime delete
f.Close()
p.Wait() p.Wait()
return nil return nil
} }

View file

@ -1,6 +1,7 @@
package runtime package runtime
import ( import (
"flag"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -9,7 +10,6 @@ import (
"syscall" "syscall"
"testing" "testing"
"time" "time"
"flag"
utils "github.com/docker/containerd/testutils" utils "github.com/docker/containerd/testutils"
) )
@ -163,13 +163,17 @@ func BenchmarkBusyboxSh(b *testing.B) {
} }
func benchmarkStartContainer(b *testing.B, c Container, s Stdio, bundleName string) { func benchmarkStartContainer(b *testing.B, c Container, s Stdio, bundleName string) {
if _, err := c.Start("", s); err != nil { p, err := c.Start("", s)
if err != nil {
b.Fatalf("Error starting container %v", err) b.Fatalf("Error starting container %v", err)
} }
kill := exec.Command(c.Runtime(), "kill", bundleName, "KILL") kill := exec.Command(c.Runtime(), "kill", bundleName, "KILL")
kill.Run() kill.Run()
p.Wait()
c.Delete()
// wait for kill to finish. selected wait time is arbitrary // wait for kill to finish. selected wait time is arbitrary
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)

View file

@ -14,6 +14,7 @@ type DeleteTask struct {
Status int Status int
PID string PID string
NoEvent bool NoEvent bool
Process runtime.Process
} }
func (s *Supervisor) delete(t *DeleteTask) error { func (s *Supervisor) delete(t *DeleteTask) error {
@ -22,6 +23,9 @@ func (s *Supervisor) delete(t *DeleteTask) error {
if err := s.deleteContainer(i.container); err != nil { if err := s.deleteContainer(i.container); err != nil {
logrus.WithField("error", err).Error("containerd: deleting container") logrus.WithField("error", err).Error("containerd: deleting container")
} }
if t.Process != nil {
t.Process.Wait()
}
if !t.NoEvent { if !t.NoEvent {
s.notifySubscribers(Event{ s.notifySubscribers(Event{
Type: StateExit, Type: StateExit,

View file

@ -49,6 +49,7 @@ func (s *Supervisor) exit(t *ExitTask) error {
ID: container.ID(), ID: container.ID(),
Status: status, Status: status,
PID: proc.ID(), PID: proc.ID(),
Process: proc,
} }
s.delete(ne) s.delete(ne)
@ -72,6 +73,7 @@ func (s *Supervisor) execExit(t *ExecExitTask) error {
if err := container.RemoveProcess(t.PID); err != nil { if err := container.RemoveProcess(t.PID); err != nil {
logrus.WithField("error", err).Error("containerd: find container for pid") logrus.WithField("error", err).Error("containerd: find container for pid")
} }
t.Process.Wait()
s.notifySubscribers(Event{ s.notifySubscribers(Event{
Timestamp: time.Now(), Timestamp: time.Now(),
ID: t.ID, ID: t.ID,

View file

@ -282,7 +282,6 @@ func (s *Supervisor) SendTask(evt Task) {
func (s *Supervisor) exitHandler() { func (s *Supervisor) exitHandler() {
for p := range s.monitor.Exits() { for p := range s.monitor.Exits() {
p.Wait()
e := &ExitTask{ e := &ExitTask{
Process: p, Process: p,
} }

View file

@ -51,6 +51,7 @@ func (w *worker) Start() {
evt := &DeleteTask{ evt := &DeleteTask{
ID: t.Container.ID(), ID: t.Container.ID(),
NoEvent: true, NoEvent: true,
Process: process,
} }
w.s.SendTask(evt) w.s.SendTask(evt)
continue continue
@ -66,6 +67,7 @@ func (w *worker) Start() {
evt := &DeleteTask{ evt := &DeleteTask{
ID: t.Container.ID(), ID: t.Container.ID(),
NoEvent: true, NoEvent: true,
Process: process,
} }
w.s.SendTask(evt) w.s.SendTask(evt)
continue continue
@ -76,6 +78,7 @@ func (w *worker) Start() {
evt := &DeleteTask{ evt := &DeleteTask{
ID: t.Container.ID(), ID: t.Container.ID(),
NoEvent: true, NoEvent: true,
Process: process,
} }
w.s.SendTask(evt) w.s.SendTask(evt)
continue continue