Skip to content

Commit

Permalink
Merge #49366
Browse files Browse the repository at this point in the history
49366: cli/quit: clean up some now-unneeded code r=tbg a=knz

Fixes #49359

Since gRPC has been updated, some error handling code was not any more
needed.

Release note: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed May 26, 2020
2 parents 8f7cd61 + bd35ab5 commit 0857bf6
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions pkg/cli/quit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"context"
"fmt"
"io"
"strings"
"time"

"github.com/cockroachdb/cockroach/pkg/server"
Expand All @@ -24,8 +23,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/errors"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// quitCmd command shuts down the node server.
Expand Down Expand Up @@ -213,7 +210,7 @@ func doShutdown(ctx context.Context, c serverpb.AdminClient) (hardError bool, er
err = errors.WithHint(err, "You can still stop the process using a service manager or a signal.")
hardError = true
}
if grpcutil.IsClosedConnection(err) || grpcConfusedErrConnClosedByPeer(err) {
if grpcutil.IsClosedConnection(err) {
// This most likely means that we shut down successfully. Note
// that sometimes the connection can be shut down even before a
// DrainResponse gets sent back to us, so we don't require a
Expand Down Expand Up @@ -256,24 +253,3 @@ func getAdminClient(ctx context.Context, cfg server.Config) (serverpb.AdminClien
}
return serverpb.NewAdminClient(conn), finish, nil
}

// grpcConfusedErrConnClosedByPeer returns true if the given error
// has been likely produced by a gRPC handshake that was confused
// by the remote end closing the connection.
// This situation occurs semi-frequently (10-15% of cases) in
// go 1.13, and may have been eliminated in 1.14.
func grpcConfusedErrConnClosedByPeer(err error) bool {
err = errors.Cause(err)
s, ok := status.FromError(err)
if !ok {
return false
}
switch {
case s.Code() == codes.Internal && strings.Contains(err.Error(), "compressed flag set with identity or empty encoding"):
return true
case s.Code() == codes.Unimplemented && strings.Contains(err.Error(), "Decompressor is not installed"):
return true
default:
return false
}
}

0 comments on commit 0857bf6

Please sign in to comment.