Merge pull request #7446 from dcantah/net-errclosed

Swap to net.ErrClosed checks for services
This commit is contained in:
Maksym Pavlenko 2022-09-29 10:55:55 -07:00 committed by GitHub
commit d71fbcf350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 10 deletions

View File

@ -22,6 +22,7 @@ package main
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"flag" "flag"
"fmt" "fmt"
"io" "io"
@ -237,8 +238,7 @@ func serve(ctx context.Context, server *ttrpc.Server, path string) error {
logrus.WithField("socket", path).Debug("serving api on unix socket") logrus.WithField("socket", path).Debug("serving api on unix socket")
go func() { go func() {
defer l.Close() defer l.Close()
if err := server.Serve(ctx, l); err != nil && if err := server.Serve(ctx, l); err != nil && !errors.Is(err, net.ErrClosed) {
!strings.Contains(err.Error(), "use of closed network connection") {
logrus.WithError(err).Fatal("containerd-shim: ttrpc server failure") logrus.WithError(err).Fatal("containerd-shim: ttrpc server failure")
} }
}() }()

View File

@ -22,11 +22,11 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"net"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"runtime/debug" "runtime/debug"
"strings"
"time" "time"
shimapi "github.com/containerd/containerd/api/runtime/task/v2" shimapi "github.com/containerd/containerd/api/runtime/task/v2"
@ -486,8 +486,7 @@ func serve(ctx context.Context, server *ttrpc.Server, signals chan os.Signal, sh
} }
go func() { go func() {
defer l.Close() defer l.Close()
if err := server.Serve(ctx, l); err != nil && if err := server.Serve(ctx, l); err != nil && !errors.Is(err, net.ErrClosed) {
!strings.Contains(err.Error(), "use of closed network connection") {
log.G(ctx).WithError(err).Fatal("containerd-shim: ttrpc server failure") log.G(ctx).WithError(err).Fatal("containerd-shim: ttrpc server failure")
} }
}() }()

View File

@ -30,7 +30,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"sync" "sync"
"time" "time"
@ -473,10 +472,7 @@ func (pc *proxyClients) getClient(address string) (*grpc.ClientConn, error) {
} }
func trapClosedConnErr(err error) error { func trapClosedConnErr(err error) error {
if err == nil { if err == nil || errors.Is(err, net.ErrClosed) {
return nil
}
if strings.Contains(err.Error(), "use of closed network connection") {
return nil return nil
} }
return err return err