Merge pull request #842 from menghanl/non_failfast_after_cc_close
Check cc.conns before reading cc.conns
This commit is contained in:
15
call_test.go
15
call_test.go
@ -276,3 +276,18 @@ func TestInvokeCancel(t *testing.T) {
|
|||||||
cc.Close()
|
cc.Close()
|
||||||
server.stop()
|
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()
|
||||||
|
}
|
||||||
|
@ -479,6 +479,10 @@ func (cc *ClientConn) getTransport(ctx context.Context, opts BalancerGetOptions)
|
|||||||
if cc.dopts.balancer == nil {
|
if cc.dopts.balancer == nil {
|
||||||
// If balancer is nil, there should be only one addrConn available.
|
// If balancer is nil, there should be only one addrConn available.
|
||||||
cc.mu.RLock()
|
cc.mu.RLock()
|
||||||
|
if cc.conns == nil {
|
||||||
|
cc.mu.RUnlock()
|
||||||
|
return nil, nil, toRPCErr(ErrClientConnClosing)
|
||||||
|
}
|
||||||
for _, ac = range cc.conns {
|
for _, ac = range cc.conns {
|
||||||
// Break after the first iteration to get the first addrConn.
|
// Break after the first iteration to get the first addrConn.
|
||||||
ok = true
|
ok = true
|
||||||
|
Reference in New Issue
Block a user