Browse code

Remove timeout on fifos opening

Instead of a timeout the context is cancelled on error to ensure
proper cleanup of the associated fifos' goroutines.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

Kenfe-Mickael Laventure authored on 2017/01/14 04:06:51
Showing 3 changed files
... ...
@@ -45,7 +45,7 @@ func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error
45 45
 // AddProcess is the handler for adding a process to an already running
46 46
 // container. It's called through docker exec. It returns the system pid of the
47 47
 // exec'd process.
48
-func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, specp Process, attachStdio StdioCallback) (int, error) {
48
+func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, specp Process, attachStdio StdioCallback) (pid int, err error) {
49 49
 	clnt.lock(containerID)
50 50
 	defer clnt.unlock(containerID)
51 51
 	container, err := clnt.getContainer(containerID)
... ...
@@ -101,7 +101,14 @@ func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendly
101 101
 		Rlimits:         convertRlimits(sp.Rlimits),
102 102
 	}
103 103
 
104
-	iopipe, err := p.openFifos(sp.Terminal)
104
+	fifoCtx, cancel := context.WithCancel(context.Background())
105
+	defer func() {
106
+		if err != nil {
107
+			cancel()
108
+		}
109
+	}()
110
+
111
+	iopipe, err := p.openFifos(fifoCtx, sp.Terminal)
105 112
 	if err != nil {
106 113
 		return -1, err
107 114
 	}
... ...
@@ -335,7 +342,14 @@ func (clnt *client) restore(cont *containerd.Container, lastEvent *containerd.Ev
335 335
 		}
336 336
 	}
337 337
 
338
-	iopipe, err := container.openFifos(terminal)
338
+	fifoCtx, cancel := context.WithCancel(context.Background())
339
+	defer func() {
340
+		if err != nil {
341
+			cancel()
342
+		}
343
+	}()
344
+
345
+	iopipe, err := container.openFifos(fifoCtx, terminal)
339 346
 	if err != nil {
340 347
 		return err
341 348
 	}
... ...
@@ -90,7 +90,7 @@ func (ctr *container) spec() (*specs.Spec, error) {
90 90
 	return &spec, nil
91 91
 }
92 92
 
93
-func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio StdioCallback) error {
93
+func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio StdioCallback) (err error) {
94 94
 	spec, err := ctr.spec()
95 95
 	if err != nil {
96 96
 		return nil
... ...
@@ -100,7 +100,14 @@ func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio
100 100
 	defer cancel()
101 101
 	ready := make(chan struct{})
102 102
 
103
-	iopipe, err := ctr.openFifos(spec.Process.Terminal)
103
+	fifoCtx, cancel := context.WithCancel(context.Background())
104
+	defer func() {
105
+		if err != nil {
106
+			cancel()
107
+		}
108
+	}()
109
+
110
+	iopipe, err := ctr.openFifos(fifoCtx, spec.Process.Terminal)
104 111
 	if err != nil {
105 112
 		return err
106 113
 	}
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"path/filepath"
10 10
 	goruntime "runtime"
11 11
 	"strings"
12
-	"time"
13 12
 
14 13
 	containerd "github.com/docker/containerd/api/grpc/types"
15 14
 	"github.com/tonistiigi/fifo"
... ...
@@ -31,13 +30,11 @@ type process struct {
31 31
 	dir string
32 32
 }
33 33
 
34
-func (p *process) openFifos(terminal bool) (pipe *IOPipe, err error) {
34
+func (p *process) openFifos(ctx context.Context, terminal bool) (pipe *IOPipe, err error) {
35 35
 	if err := os.MkdirAll(p.dir, 0700); err != nil {
36 36
 		return nil, err
37 37
 	}
38 38
 
39
-	ctx, _ := context.WithTimeout(context.Background(), 15*time.Second)
40
-
41 39
 	io := &IOPipe{}
42 40
 
43 41
 	io.Stdin, err = fifo.OpenFifo(ctx, p.fifo(unix.Stdin), unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)