vendor: update grpc/grpc-go for clientconn patch

This commit is contained in:
Gyu-Ho Lee 2016-08-18 20:17:24 -07:00
parent f4b6ed2469
commit 01471481a9
5 changed files with 48 additions and 35 deletions

View File

@ -170,9 +170,9 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
if _, ok := err.(*rpcError); ok { if _, ok := err.(*rpcError); ok {
return err return err
} }
if err == errConnClosing { if err == errConnClosing || err == errConnUnavailable {
if c.failFast { if c.failFast {
return Errorf(codes.Unavailable, "%v", errConnClosing) return Errorf(codes.Unavailable, "%v", err)
} }
continue continue
} }

View File

@ -73,7 +73,9 @@ var (
errConnDrain = errors.New("grpc: the connection is drained") errConnDrain = errors.New("grpc: the connection is drained")
// errConnClosing indicates that the connection is closing. // errConnClosing indicates that the connection is closing.
errConnClosing = errors.New("grpc: the connection is closing") errConnClosing = errors.New("grpc: the connection is closing")
errNoAddr = errors.New("grpc: there is no address available to dial") // errConnUnavailable indicates that the connection is unavailable.
errConnUnavailable = errors.New("grpc: the connection is unavailable")
errNoAddr = errors.New("grpc: there is no address available to dial")
// minimum time to give a connection to complete // minimum time to give a connection to complete
minConnectTimeout = 20 * time.Second minConnectTimeout = 20 * time.Second
) )
@ -213,9 +215,14 @@ func WithUserAgent(s string) DialOption {
} }
} }
// Dial creates a client connection the given target. // Dial creates a client connection to the given target.
func Dial(target string, opts ...DialOption) (*ClientConn, error) { func Dial(target string, opts ...DialOption) (*ClientConn, error) {
ctx := context.Background() return DialContext(context.Background(), target, opts...)
}
// DialContext creates a client connection to the given target
// using the supplied context.
func DialContext(ctx context.Context, target string, opts ...DialOption) (*ClientConn, error) {
cc := &ClientConn{ cc := &ClientConn{
target: target, target: target,
conns: make(map[Address]*addrConn), conns: make(map[Address]*addrConn),
@ -472,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
@ -501,11 +512,7 @@ func (cc *ClientConn) getTransport(ctx context.Context, opts BalancerGetOptions)
} }
return nil, nil, errConnClosing return nil, nil, errConnClosing
} }
// ac.wait should block on transient failure only if balancer is nil and RPC is non-failfast. t, err := ac.wait(ctx, cc.dopts.balancer != nil, !opts.BlockingWait)
// - If RPC is failfast, ac.wait should not block.
// - If balancer is not nil, ac.wait should return errConnClosing on transient failure
// so that non-failfast RPCs will try to get a new transport instead of waiting on ac.
t, err := ac.wait(ctx, cc.dopts.balancer == nil && opts.BlockingWait)
if err != nil { if err != nil {
if put != nil { if put != nil {
put() put()
@ -757,36 +764,42 @@ func (ac *addrConn) transportMonitor() {
} }
// wait blocks until i) the new transport is up or ii) ctx is done or iii) ac is closed or // wait blocks until i) the new transport is up or ii) ctx is done or iii) ac is closed or
// iv) transport is in TransientFailure and blocking is false. // iv) transport is in TransientFailure and there's no balancer/failfast is true.
func (ac *addrConn) wait(ctx context.Context, blocking bool) (transport.ClientTransport, error) { func (ac *addrConn) wait(ctx context.Context, hasBalancer, failfast bool) (transport.ClientTransport, error) {
for { for {
ac.mu.Lock() ac.mu.Lock()
switch { switch {
case ac.state == Shutdown: case ac.state == Shutdown:
err := ac.tearDownErr if failfast || !hasBalancer {
// RPC is failfast or balancer is nil. This RPC should fail with ac.tearDownErr.
err := ac.tearDownErr
ac.mu.Unlock()
return nil, err
}
ac.mu.Unlock() ac.mu.Unlock()
return nil, err return nil, errConnClosing
case ac.state == Ready: case ac.state == Ready:
ct := ac.transport ct := ac.transport
ac.mu.Unlock() ac.mu.Unlock()
return ct, nil return ct, nil
case ac.state == TransientFailure && !blocking: case ac.state == TransientFailure:
ac.mu.Unlock() if failfast || hasBalancer {
return nil, errConnClosing ac.mu.Unlock()
default: return nil, errConnUnavailable
ready := ac.ready
if ready == nil {
ready = make(chan struct{})
ac.ready = ready
}
ac.mu.Unlock()
select {
case <-ctx.Done():
return nil, toRPCErr(ctx.Err())
// Wait until the new transport is ready or failed.
case <-ready:
} }
} }
ready := ac.ready
if ready == nil {
ready = make(chan struct{})
ac.ready = ready
}
ac.mu.Unlock()
select {
case <-ctx.Done():
return nil, toRPCErr(ctx.Err())
// Wait until the new transport is ready or failed.
case <-ready:
}
} }
} }

View File

@ -146,9 +146,9 @@ func NewClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
if _, ok := err.(*rpcError); ok { if _, ok := err.(*rpcError); ok {
return nil, err return nil, err
} }
if err == errConnClosing { if err == errConnClosing || err == errConnUnavailable {
if c.failFast { if c.failFast {
return nil, Errorf(codes.Unavailable, "%v", errConnClosing) return nil, Errorf(codes.Unavailable, "%v", err)
} }
continue continue
} }

6
glide.lock generated
View File

@ -1,5 +1,5 @@
hash: 0137d778163228de7f49ff31f4ec0f1f3b9c315d16a9f2e2d6d7a2ca41f968cf hash: 9d37c5aecd92dfa9b789162e389d87564aa7e7a18f9c1f14ea57d06c0165a1cf
updated: 2016-08-18T10:30:07.68579351-07:00 updated: 2016-08-18T20:16:50.783927627-07:00
imports: imports:
- name: bitbucket.org/ww/goautoneg - name: bitbucket.org/ww/goautoneg
version: 75cd24fc2f2c2a2088577d12123ddee5f54e0675 version: 75cd24fc2f2c2a2088577d12123ddee5f54e0675
@ -136,7 +136,7 @@ imports:
subpackages: subpackages:
- rate - rate
- name: google.golang.org/grpc - name: google.golang.org/grpc
version: c2781963b3af261a37e0f14fdcb7c1fa13259e1f version: 231b4cfea0e79843053a33f5fe90bd4d84b23cd3
subpackages: subpackages:
- codes - codes
- credentials - credentials

View File

@ -134,7 +134,7 @@ import:
subpackages: subpackages:
- rate - rate
- package: google.golang.org/grpc - package: google.golang.org/grpc
version: c2781963b3af261a37e0f14fdcb7c1fa13259e1f version: 231b4cfea0e79843053a33f5fe90bd4d84b23cd3
subpackages: subpackages:
- codes - codes
- credentials - credentials