Merge pull request #5174 from fuweid/fix-5130

runtime: ignore file-already-closed error if dead shim
This commit is contained in:
Phil Estes 2021-03-15 10:38:41 -04:00 committed by GitHub
commit fad66f94ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View File

@ -84,7 +84,7 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
}() }()
f, err := openShimLog(shimCtx, bundle, client.AnonReconnectDialer) f, err := openShimLog(shimCtx, bundle, client.AnonReconnectDialer)
if err != nil { 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() { defer func() {
if err != nil { if err != nil {
@ -96,13 +96,10 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
// copy the shim's logs to containerd's output // copy the shim's logs to containerd's output
go func() { go func() {
defer f.Close() defer f.Close()
if _, err := io.Copy(os.Stderr, f); err != nil { _, err := io.Copy(os.Stderr, f)
// When using a multi-container shim the 2nd to Nth container in the err = checkCopyShimLogError(ctx, err)
// shim will not have a separate log pipe. Ignore the failure log if err != nil {
// message here when the shim connect times out. log.G(ctx).WithError(err).Error("copy shim log after reload")
if !errors.Is(err, os.ErrNotExist) {
log.G(ctx).WithError(err).Error("copy shim log")
}
} }
}() }()
onCloseWithShimLog := func() { onCloseWithShimLog := func() {

View File

@ -22,10 +22,12 @@ import (
"context" "context"
"io" "io"
"net" "net"
"os"
"path/filepath" "path/filepath"
"time" "time"
"github.com/containerd/fifo" "github.com/containerd/fifo"
"github.com/pkg/errors"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -34,12 +36,9 @@ func openShimLog(ctx context.Context, bundle *Bundle, _ func(string, time.Durati
} }
func checkCopyShimLogError(ctx context.Context, err error) error { func checkCopyShimLogError(ctx context.Context, err error) error {
// When using a multi-container shim, the fifo of the 2nd to Nth
// container will not be opened when the ctx is done. This will
// cause an ErrReadClosed that can be ignored.
select { select {
case <-ctx.Done(): case <-ctx.Done():
if err == fifo.ErrReadClosed { if err == fifo.ErrReadClosed || errors.Is(err, os.ErrClosed) {
return nil return nil
} }
default: default:

View File

@ -20,6 +20,7 @@ package v2
import ( import (
"context" "context"
"os"
"testing" "testing"
"github.com/containerd/fifo" "github.com/containerd/fifo"
@ -43,6 +44,9 @@ func TestCheckCopyShimLogError(t *testing.T) {
if err := checkCopyShimLogError(ctx, nil); err != nil { if err := checkCopyShimLogError(ctx, nil); err != nil {
t.Fatalf("should return the actual error after context is done, but %v", err) 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 { if err := checkCopyShimLogError(ctx, fifo.ErrRdFrmWRONLY); err != fifo.ErrRdFrmWRONLY {
t.Fatalf("should return the actual error after context is done, but %v", err) t.Fatalf("should return the actual error after context is done, but %v", err)
} }