Skip to content

Commit fad66f9

Browse files
authored
Merge pull request #5174 from fuweid/fix-5130
runtime: ignore file-already-closed error if dead shim
2 parents bd4f468 + eabd9b9 commit fad66f9

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

runtime/v2/shim.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
8484
}()
8585
f, err := openShimLog(shimCtx, bundle, client.AnonReconnectDialer)
8686
if err != nil {
87-
return nil, errors.Wrap(err, "open shim log pipe")
87+
return nil, errors.Wrap(err, "open shim log pipe when reload")
8888
}
8989
defer func() {
9090
if err != nil {
@@ -96,13 +96,10 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
9696
// copy the shim's logs to containerd's output
9797
go func() {
9898
defer f.Close()
99-
if _, err := io.Copy(os.Stderr, f); err != nil {
100-
// When using a multi-container shim the 2nd to Nth container in the
101-
// shim will not have a separate log pipe. Ignore the failure log
102-
// message here when the shim connect times out.
103-
if !errors.Is(err, os.ErrNotExist) {
104-
log.G(ctx).WithError(err).Error("copy shim log")
105-
}
99+
_, err := io.Copy(os.Stderr, f)
100+
err = checkCopyShimLogError(ctx, err)
101+
if err != nil {
102+
log.G(ctx).WithError(err).Error("copy shim log after reload")
106103
}
107104
}()
108105
onCloseWithShimLog := func() {

runtime/v2/shim_unix.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import (
2222
"context"
2323
"io"
2424
"net"
25+
"os"
2526
"path/filepath"
2627
"time"
2728

2829
"github.com/containerd/fifo"
30+
"github.com/pkg/errors"
2931
"golang.org/x/sys/unix"
3032
)
3133

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

3638
func checkCopyShimLogError(ctx context.Context, err error) error {
37-
// When using a multi-container shim, the fifo of the 2nd to Nth
38-
// container will not be opened when the ctx is done. This will
39-
// cause an ErrReadClosed that can be ignored.
4039
select {
4140
case <-ctx.Done():
42-
if err == fifo.ErrReadClosed {
41+
if err == fifo.ErrReadClosed || errors.Is(err, os.ErrClosed) {
4342
return nil
4443
}
4544
default:

runtime/v2/shim_unix_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package v2
2020

2121
import (
2222
"context"
23+
"os"
2324
"testing"
2425

2526
"github.com/containerd/fifo"
@@ -43,6 +44,9 @@ func TestCheckCopyShimLogError(t *testing.T) {
4344
if err := checkCopyShimLogError(ctx, nil); err != nil {
4445
t.Fatalf("should return the actual error after context is done, but %v", err)
4546
}
47+
if err := checkCopyShimLogError(ctx, os.ErrClosed); err != nil {
48+
t.Fatalf("should return the actual error after context is done, but %v", err)
49+
}
4650
if err := checkCopyShimLogError(ctx, fifo.ErrRdFrmWRONLY); err != fifo.ErrRdFrmWRONLY {
4751
t.Fatalf("should return the actual error after context is done, but %v", err)
4852
}

0 commit comments

Comments
 (0)