Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions runtime/v2/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
}()
f, err := openShimLog(shimCtx, bundle, client.AnonReconnectDialer)
if err != nil {
return nil, errors.Wrap(err, "open shim log pipe")
return nil, errors.Wrap(err, "open shim log pipe when reload")
}
defer func() {
if err != nil {
Expand All @@ -96,13 +96,10 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
// copy the shim's logs to containerd's output
go func() {
defer f.Close()
if _, err := io.Copy(os.Stderr, f); err != nil {
// When using a multi-container shim the 2nd to Nth container in the
// shim will not have a separate log pipe. Ignore the failure log
// message here when the shim connect times out.
if !errors.Is(err, os.ErrNotExist) {
log.G(ctx).WithError(err).Error("copy shim log")
}
_, err := io.Copy(os.Stderr, f)
err = checkCopyShimLogError(ctx, err)
if err != nil {
log.G(ctx).WithError(err).Error("copy shim log after reload")
}
}()
onCloseWithShimLog := func() {
Expand Down
7 changes: 3 additions & 4 deletions runtime/v2/shim_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (
"context"
"io"
"net"
"os"
"path/filepath"
"time"

"github.com/containerd/fifo"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

Expand All @@ -34,12 +36,9 @@ func openShimLog(ctx context.Context, bundle *Bundle, _ func(string, time.Durati
}

func checkCopyShimLogError(ctx context.Context, err error) error {
// When using a multi-container shim, the fifo of the 2nd to Nth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comments because of #4906

// container will not be opened when the ctx is done. This will
// cause an ErrReadClosed that can be ignored.
select {
case <-ctx.Done():
if err == fifo.ErrReadClosed {
if err == fifo.ErrReadClosed || errors.Is(err, os.ErrClosed) {
return nil
}
default:
Expand Down
4 changes: 4 additions & 0 deletions runtime/v2/shim_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package v2

import (
"context"
"os"
"testing"

"github.com/containerd/fifo"
Expand All @@ -43,6 +44,9 @@ func TestCheckCopyShimLogError(t *testing.T) {
if err := checkCopyShimLogError(ctx, nil); err != nil {
t.Fatalf("should return the actual error after context is done, but %v", err)
}
if err := checkCopyShimLogError(ctx, os.ErrClosed); err != nil {
t.Fatalf("should return the actual error after context is done, but %v", err)
}
if err := checkCopyShimLogError(ctx, fifo.ErrRdFrmWRONLY); err != fifo.ErrRdFrmWRONLY {
t.Fatalf("should return the actual error after context is done, but %v", err)
}
Expand Down