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>
This commit is contained in:
parent
f858d49483
commit
c178700a04
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
|
||||
// container. It's called through docker exec. It returns the system pid of the
|
||||
// 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)
|
||||
defer clnt.unlock(containerID)
|
||||
container, err := clnt.getContainer(containerID)
|
||||
|
@ -101,7 +101,14 @@ func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendly
|
|||
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 {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func (ctr *container) spec() (*specs.Spec, error) {
|
|||
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()
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -100,7 +100,14 @@ func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio
|
|||
defer cancel()
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"path/filepath"
|
||||
goruntime "runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
containerd "github.com/docker/containerd/api/grpc/types"
|
||||
"github.com/tonistiigi/fifo"
|
||||
|
@ -31,13 +30,11 @@ type process struct {
|
|||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
|
||||
io := &IOPipe{}
|
||||
|
||||
io.Stdin, err = fifo.OpenFifo(ctx, p.fifo(unix.Stdin), unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
|
||||
|
|
Loading…
Reference in a new issue