Skip to content

Commit

Permalink
Merge pull request grpc#842 from menghanl/non_failfast_after_cc_close
Browse files Browse the repository at this point in the history
Check cc.conns before reading cc.conns
  • Loading branch information
iamqizhao committed Aug 19, 2016
2 parents 2e4cfe0 + f3ac95e commit 231b4cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,18 @@ func TestInvokeCancel(t *testing.T) {
cc.Close()
server.stop()
}

// TestInvokeCancelClosedNonFail checks that a canceled non-failfast RPC
// on a closed client will terminate.
func TestInvokeCancelClosedNonFailFast(t *testing.T) {
server, cc := setUp(t, 0, math.MaxUint32)
var reply string
cc.Close()
req := "hello"
ctx, cancel := context.WithCancel(context.Background())
cancel()
if err := Invoke(ctx, "/foo/bar", &req, &reply, cc, FailFast(false)); err == nil {
t.Fatalf("canceled invoke on closed connection should fail")
}
server.stop()
}
4 changes: 4 additions & 0 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ func (cc *ClientConn) getTransport(ctx context.Context, opts BalancerGetOptions)
if cc.dopts.balancer == nil {
// If balancer is nil, there should be only one addrConn available.
cc.mu.RLock()
if cc.conns == nil {
cc.mu.RUnlock()
return nil, nil, toRPCErr(ErrClientConnClosing)
}
for _, ac = range cc.conns {
// Break after the first iteration to get the first addrConn.
ok = true
Expand Down

0 comments on commit 231b4cf

Please sign in to comment.