Fix potential panic for task in unknown state.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
95301fee3a
commit
c410f0eaef
@ -72,17 +72,19 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var wg = &sync.WaitGroup{}
|
var wg = &sync.WaitGroup{}
|
||||||
wg.Add(1)
|
if fifos.Stdout != "" {
|
||||||
go func() {
|
wg.Add(1)
|
||||||
p := bufPool.Get().(*[]byte)
|
go func() {
|
||||||
defer bufPool.Put(p)
|
p := bufPool.Get().(*[]byte)
|
||||||
|
defer bufPool.Put(p)
|
||||||
|
|
||||||
io.CopyBuffer(ioset.Stdout, pipes.Stdout, *p)
|
io.CopyBuffer(ioset.Stdout, pipes.Stdout, *p)
|
||||||
pipes.Stdout.Close()
|
pipes.Stdout.Close()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if !fifos.Terminal {
|
if !fifos.Terminal && fifos.Stderr != "" {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
p := bufPool.Get().(*[]byte)
|
p := bufPool.Get().(*[]byte)
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd/api/services/tasks/v1"
|
"github.com/containerd/containerd/api/services/tasks/v1"
|
||||||
"github.com/containerd/containerd/api/types"
|
"github.com/containerd/containerd/api/types"
|
||||||
|
tasktypes "github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
@ -382,7 +383,9 @@ func (c *container) loadTask(ctx context.Context, ioAttach cio.Attach) (Task, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var i cio.IO
|
var i cio.IO
|
||||||
if ioAttach != nil {
|
if ioAttach != nil && response.Process.Status != tasktypes.StatusUnknown {
|
||||||
|
// Do not attach IO for task in unknown state, because there
|
||||||
|
// are no fifo paths anyway.
|
||||||
if i, err = attachExistingIO(response, ioAttach); err != nil {
|
if i, err = attachExistingIO(response, ioAttach); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user