Swap to net.ErrClosed checks for services
In Go 1.16 `net.ErrClosed` was exported, removing the need to check the exact text of "use of closed network connection". The stdlib's net listeners are all setup for this to be a reality, but on Windows containerd uses the the go-winio projects named pipe implementation as the listener for services. Before version 0.6.0 this project returned a different error named `ErrPipeListenerClosed` for using a closed pipe, where this error was just an `errors.New` with the same text as `net.ErrClosed`, so checking against `net.ErrClosed` wasn't possible. Starting in 0.6.0 go-winio has that error assigned to `net.ErrClosed` directly so this *should* be alright to finally change. Signed-off-by: Daniel Canter <dcanter@microsoft.com>
This commit is contained in:
parent
7374e0a330
commit
4333e6a6d6
@ -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")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -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")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user