X Tutup
Skip to content

Commit c410f0e

Browse files
committed
Fix potential panic for task in unknown state.
Signed-off-by: Lantao Liu <lantaol@google.com>
1 parent 95301fe commit c410f0e

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

cio/io_unix.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,19 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
7272
}
7373

7474
var wg = &sync.WaitGroup{}
75-
wg.Add(1)
76-
go func() {
77-
p := bufPool.Get().(*[]byte)
78-
defer bufPool.Put(p)
79-
80-
io.CopyBuffer(ioset.Stdout, pipes.Stdout, *p)
81-
pipes.Stdout.Close()
82-
wg.Done()
83-
}()
75+
if fifos.Stdout != "" {
76+
wg.Add(1)
77+
go func() {
78+
p := bufPool.Get().(*[]byte)
79+
defer bufPool.Put(p)
80+
81+
io.CopyBuffer(ioset.Stdout, pipes.Stdout, *p)
82+
pipes.Stdout.Close()
83+
wg.Done()
84+
}()
85+
}
8486

85-
if !fifos.Terminal {
87+
if !fifos.Terminal && fifos.Stderr != "" {
8688
wg.Add(1)
8789
go func() {
8890
p := bufPool.Get().(*[]byte)

container.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/containerd/containerd/api/services/tasks/v1"
2727
"github.com/containerd/containerd/api/types"
28+
tasktypes "github.com/containerd/containerd/api/types/task"
2829
"github.com/containerd/containerd/cio"
2930
"github.com/containerd/containerd/containers"
3031
"github.com/containerd/containerd/errdefs"
@@ -382,7 +383,9 @@ func (c *container) loadTask(ctx context.Context, ioAttach cio.Attach) (Task, er
382383
return nil, err
383384
}
384385
var i cio.IO
385-
if ioAttach != nil {
386+
if ioAttach != nil && response.Process.Status != tasktypes.StatusUnknown {
387+
// Do not attach IO for task in unknown state, because there
388+
// are no fifo paths anyway.
386389
if i, err = attachExistingIO(response, ioAttach); err != nil {
387390
return nil, err
388391
}

0 commit comments

Comments
 (0)
X Tutup