From 01ef81a4d918548bff15b1d6df8bc17620fea3c7 Mon Sep 17 00:00:00 2001 From: iamqizhao Date: Mon, 27 Jun 2016 15:30:20 -0700 Subject: [PATCH] minor fix including removal of debugging logs, error code fix, etc. --- balancer.go | 1 - call.go | 3 --- clientconn.go | 4 ++-- rpc_util.go | 5 +++-- test/end2end_test.go | 10 +++++----- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/balancer.go b/balancer.go index 307e3dc1..8c588785 100644 --- a/balancer.go +++ b/balancer.go @@ -298,7 +298,6 @@ func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Ad } } } - // There is no address available. if !opts.BlockingWait { if len(rr.addrs) == 0 { rr.mu.Unlock() diff --git a/call.go b/call.go index fb2144b2..baa912dd 100644 --- a/call.go +++ b/call.go @@ -35,7 +35,6 @@ package grpc import ( "bytes" - //"fmt" "io" "time" @@ -170,8 +169,6 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli } // ALl the other errors are treated as Internal errors. return Errorf(codes.Internal, "%v", err) - // All the remaining cases are treated as fatal. - //panic(fmt.Sprintf("ClientConn.getTransport got an unsupported error: %v", err)) } if c.traceInfo.tr != nil { c.traceInfo.tr.LazyLog(&payload{sent: true, msg: args}, true) diff --git a/clientconn.go b/clientconn.go index 79965ec3..864abab7 100644 --- a/clientconn.go +++ b/clientconn.go @@ -664,7 +664,7 @@ func (ac *addrConn) wait(ctx context.Context, failFast bool) (transport.ClientTr default: if ac.state == TransientFailure && failFast { ac.mu.Unlock() - return nil, transport.StreamErrorf(codes.Canceled, "grpc: RPC failed fast due to transport failure") + return nil, transport.StreamErrorf(codes.Unavailable, "grpc: RPC failed fast due to transport failure") } ready := ac.ready if ready == nil { @@ -680,7 +680,7 @@ func (ac *addrConn) wait(ctx context.Context, failFast bool) (transport.ClientTr ac.mu.Lock() if ac.state == TransientFailure && failFast { ac.mu.Unlock() - return nil, transport.StreamErrorf(codes.Canceled, "grpc: RPC failed fast due to transport failure") + return nil, transport.StreamErrorf(codes.Unavailable, "grpc: RPC failed fast due to transport failure") } ac.mu.Unlock() diff --git a/rpc_util.go b/rpc_util.go index 36c60183..3bdc7c84 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -183,9 +183,10 @@ func Trailer(md *metadata.MD) CallOption { // FailFast configures the action to take when an RPC is attempted on broken // connections or unreachable servers. If failfast is true, the RPC will fail -// immediately. Otherwise, the RPC client will block the call until a +// immediately. Otherwise, the RPC client will block the call until a // connection is available (or the call is canceled or times out) and will retry -// the call if it fails due to a transient error. +// the call if it fails due to a transient error. Please refer to +// https://github.com/grpc/grpc/blob/master/doc/fail_fast.md func FailFast(failFast bool) CallOption { return beforeCall(func(c *callInfo) error { c.failFast = failFast diff --git a/test/end2end_test.go b/test/end2end_test.go index 5a0759f8..8e399262 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -595,12 +595,12 @@ func testFailFast(t *testing.T, e env) { if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.FailFast(false)); grpc.Code(err) != codes.DeadlineExceeded { t.Fatalf("TestService/EmptyCall(%v, _) = _, %v, want _, error code: %d", ctx, err, codes.DeadlineExceeded) } - // The client keeps reconnecting and ongoing fail-fast RPCs should fail with code.Canceled. - if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); grpc.Code(err) != codes.Canceled { - t.Fatalf("TestService/EmptyCall(_, _, _) = _, %v, want _, error code: %d", err, codes.Canceled) + // The client keeps reconnecting and ongoing fail-fast RPCs should fail with code.Unavailable. + if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); grpc.Code(err) != codes.Unavailable { + t.Fatalf("TestService/EmptyCall(_, _, _) = _, %v, want _, error code: %d", err, codes.Unavailable) } - if _, err := tc.StreamingInputCall(ctx); grpc.Code(err) != codes.Canceled { - t.Fatalf("TestService/StreamingInputCall(_) = _, %v, want _, error code: %d", err, codes.Canceled) + if _, err := tc.StreamingInputCall(ctx); grpc.Code(err) != codes.Unavailable { + t.Fatalf("TestService/StreamingInputCall(_) = _, %v, want _, error code: %d", err, codes.Unavailable) } awaitNewConnLogOutput()