Bläddra i källkod

Merge pull request #30140 from mlaventure/remove-fifo-timeout

Remove timeout on fifos opening
Sebastiaan van Stijn 8 år sedan
förälder
incheckning
582c5b7652
3 ändrade filer med 27 tillägg och 9 borttagningar
  1. 17 3
      libcontainerd/client_linux.go
  2. 9 2
      libcontainerd/container_unix.go
  3. 1 4
      libcontainerd/process_unix.go

+ 17 - 3
libcontainerd/client_linux.go

@@ -45,7 +45,7 @@ func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error
 // AddProcess is the handler for adding a process to an already running
 // AddProcess is the handler for adding a process to an already running
 // container. It's called through docker exec. It returns the system pid of the
 // container. It's called through docker exec. It returns the system pid of the
 // exec'd process.
 // exec'd process.
-func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, specp Process, attachStdio StdioCallback) (int, error) {
+func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, specp Process, attachStdio StdioCallback) (pid int, err error) {
 	clnt.lock(containerID)
 	clnt.lock(containerID)
 	defer clnt.unlock(containerID)
 	defer clnt.unlock(containerID)
 	container, err := clnt.getContainer(containerID)
 	container, err := clnt.getContainer(containerID)
@@ -101,7 +101,14 @@ func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendly
 		Rlimits:         convertRlimits(sp.Rlimits),
 		Rlimits:         convertRlimits(sp.Rlimits),
 	}
 	}
 
 
-	iopipe, err := p.openFifos(sp.Terminal)
+	fifoCtx, cancel := context.WithCancel(context.Background())
+	defer func() {
+		if err != nil {
+			cancel()
+		}
+	}()
+
+	iopipe, err := p.openFifos(fifoCtx, sp.Terminal)
 	if err != nil {
 	if err != nil {
 		return -1, err
 		return -1, err
 	}
 	}
@@ -335,7 +342,14 @@ func (clnt *client) restore(cont *containerd.Container, lastEvent *containerd.Ev
 		}
 		}
 	}
 	}
 
 
-	iopipe, err := container.openFifos(terminal)
+	fifoCtx, cancel := context.WithCancel(context.Background())
+	defer func() {
+		if err != nil {
+			cancel()
+		}
+	}()
+
+	iopipe, err := container.openFifos(fifoCtx, terminal)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 9 - 2
libcontainerd/container_unix.go

@@ -90,7 +90,7 @@ func (ctr *container) spec() (*specs.Spec, error) {
 	return &spec, nil
 	return &spec, nil
 }
 }
 
 
-func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio StdioCallback) error {
+func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio StdioCallback) (err error) {
 	spec, err := ctr.spec()
 	spec, err := ctr.spec()
 	if err != nil {
 	if err != nil {
 		return nil
 		return nil
@@ -100,7 +100,14 @@ func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio
 	defer cancel()
 	defer cancel()
 	ready := make(chan struct{})
 	ready := make(chan struct{})
 
 
-	iopipe, err := ctr.openFifos(spec.Process.Terminal)
+	fifoCtx, cancel := context.WithCancel(context.Background())
+	defer func() {
+		if err != nil {
+			cancel()
+		}
+	}()
+
+	iopipe, err := ctr.openFifos(fifoCtx, spec.Process.Terminal)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 1 - 4
libcontainerd/process_unix.go

@@ -9,7 +9,6 @@ import (
 	"path/filepath"
 	"path/filepath"
 	goruntime "runtime"
 	goruntime "runtime"
 	"strings"
 	"strings"
-	"time"
 
 
 	containerd "github.com/docker/containerd/api/grpc/types"
 	containerd "github.com/docker/containerd/api/grpc/types"
 	"github.com/tonistiigi/fifo"
 	"github.com/tonistiigi/fifo"
@@ -31,13 +30,11 @@ type process struct {
 	dir string
 	dir string
 }
 }
 
 
-func (p *process) openFifos(terminal bool) (pipe *IOPipe, err error) {
+func (p *process) openFifos(ctx context.Context, terminal bool) (pipe *IOPipe, err error) {
 	if err := os.MkdirAll(p.dir, 0700); err != nil {
 	if err := os.MkdirAll(p.dir, 0700); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	ctx, _ := context.WithTimeout(context.Background(), 15*time.Second)
-
 	io := &IOPipe{}
 	io := &IOPipe{}
 
 
 	io.Stdin, err = fifo.OpenFifo(ctx, p.fifo(unix.Stdin), unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
 	io.Stdin, err = fifo.OpenFifo(ctx, p.fifo(unix.Stdin), unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)