MCPcopy
hub / github.com/grpc/grpc-go / tryAllAddrs

Method tryAllAddrs

clientconn.go:1452–1485  ·  view source on GitHub ↗

tryAllAddrs tries to create a connection to the addresses, and stop when at the first successful one. It returns an error if no address was successfully connected, or updates ac appropriately with the new transport.

(ctx context.Context, addrs []resolver.Address, connectDeadline time.Time)

Source from the content-addressed store, hash-verified

1450// the first successful one. It returns an error if no address was successfully
1451// connected, or updates ac appropriately with the new transport.
1452func (ac *addrConn) tryAllAddrs(ctx context.Context, addrs []resolver.Address, connectDeadline time.Time) error {
1453 var firstConnErr error
1454 for _, addr := range addrs {
1455 ac.channelz.ChannelMetrics.Target.Store(&addr.Addr)
1456 if ctx.Err() != nil {
1457 return errConnClosing
1458 }
1459 ac.mu.Lock()
1460
1461 ac.cc.mu.RLock()
1462 ac.dopts.copts.KeepaliveParams = ac.cc.keepaliveParams
1463 ac.cc.mu.RUnlock()
1464
1465 copts := ac.dopts.copts
1466 if ac.scopts.CredsBundle != nil {
1467 copts.CredsBundle = ac.scopts.CredsBundle
1468 }
1469 ac.mu.Unlock()
1470
1471 channelz.Infof(logger, ac.channelz, "Subchannel picks a new address %q to connect", addr.Addr)
1472
1473 err := ac.createTransport(ctx, addr, copts, connectDeadline)
1474 if err == nil {
1475 return nil
1476 }
1477 if firstConnErr == nil {
1478 firstConnErr = err
1479 }
1480 ac.cc.updateConnectionError(err)
1481 }
1482
1483 // Couldn't connect to any address.
1484 return firstConnErr
1485}
1486
1487// createTransport creates a connection to addr. It returns an error if the
1488// address was not successfully connected, or updates ac appropriately with the

Callers 1

Calls 6

createTransportMethod · 0.95
InfofFunction · 0.92
ErrMethod · 0.80
updateConnectionErrorMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected