Skip to content

Commit

Permalink
Fix shim deadlock when joining an existing pid namespace (#290)
Browse files Browse the repository at this point in the history
Signed-off-by: Kenfe-Mickael Laventure <[email protected]>
  • Loading branch information
mlaventure authored and crosbymichael committed Jul 15, 2016
1 parent 3abb9fc commit 0ac3cd1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions containerd-shim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func start(log *os.File) error {
// runtime has exited so the shim can also exit
if exitShim {
// Let containerd take care of calling the runtime delete
f.Close()
p.Wait()
return nil
}
Expand Down
12 changes: 8 additions & 4 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package runtime

import (
"flag"
"fmt"
"io"
"os"
Expand All @@ -9,14 +10,13 @@ import (
"syscall"
"testing"
"time"
"flag"

utils "github.com/docker/containerd/testutils"
)

var (
devNull = "/dev/null"
stdin io.WriteCloser
devNull = "/dev/null"
stdin io.WriteCloser
runtimeTool = flag.String("runtime", "runc", "Runtime to use for this test")
)

Expand Down Expand Up @@ -163,13 +163,17 @@ func BenchmarkBusyboxSh(b *testing.B) {
}

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)
}

kill := exec.Command(c.Runtime(), "kill", bundleName, "KILL")
kill.Run()

p.Wait()
c.Delete()

// wait for kill to finish. selected wait time is arbitrary
time.Sleep(500 * time.Millisecond)

Expand Down
4 changes: 4 additions & 0 deletions supervisor/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type DeleteTask struct {
Status int
PID string
NoEvent bool
Process runtime.Process
}

func (s *Supervisor) delete(t *DeleteTask) error {
Expand All @@ -22,6 +23,9 @@ func (s *Supervisor) delete(t *DeleteTask) error {
if err := s.deleteContainer(i.container); err != nil {
logrus.WithField("error", err).Error("containerd: deleting container")
}
if t.Process != nil {
t.Process.Wait()
}
if !t.NoEvent {
s.notifySubscribers(Event{
Type: StateExit,
Expand Down
8 changes: 5 additions & 3 deletions supervisor/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func (s *Supervisor) exit(t *ExitTask) error {
}
container := proc.Container()
ne := &DeleteTask{
ID: container.ID(),
Status: status,
PID: proc.ID(),
ID: container.ID(),
Status: status,
PID: proc.ID(),
Process: proc,
}
s.delete(ne)

Expand All @@ -72,6 +73,7 @@ func (s *Supervisor) execExit(t *ExecExitTask) error {
if err := container.RemoveProcess(t.PID); err != nil {
logrus.WithField("error", err).Error("containerd: find container for pid")
}
t.Process.Wait()
s.notifySubscribers(Event{
Timestamp: time.Now(),
ID: t.ID,
Expand Down
1 change: 0 additions & 1 deletion supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ func (s *Supervisor) SendTask(evt Task) {

func (s *Supervisor) exitHandler() {
for p := range s.monitor.Exits() {
p.Wait()
e := &ExitTask{
Process: p,
}
Expand Down
3 changes: 3 additions & 0 deletions supervisor/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (w *worker) Start() {
evt := &DeleteTask{
ID: t.Container.ID(),
NoEvent: true,
Process: process,
}
w.s.SendTask(evt)
continue
Expand All @@ -66,6 +67,7 @@ func (w *worker) Start() {
evt := &DeleteTask{
ID: t.Container.ID(),
NoEvent: true,
Process: process,
}
w.s.SendTask(evt)
continue
Expand All @@ -76,6 +78,7 @@ func (w *worker) Start() {
evt := &DeleteTask{
ID: t.Container.ID(),
NoEvent: true,
Process: process,
}
w.s.SendTask(evt)
continue
Expand Down

0 comments on commit 0ac3cd1

Please sign in to comment.