mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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>
(cherry picked from commit c178700a04
)
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
37be2d4e9b
commit
25810f3f47
3 changed files with 27 additions and 9 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue