Lines Matching refs:ac
862 ac := &addrConn{
867 ac.ctx, ac.cancel = context.WithCancel(cc.ctx)
875 ac.channelzID = channelz.RegisterSubChannel(ac, cc.channelzID, "")
877 cc.conns[ac] = struct{}{}
879 return ac, nil
884 func (cc *ClientConn) removeAddrConn(ac *addrConn, err error) {
890 delete(cc.conns, ac)
892 ac.tearDown(err)
936 func (ac *addrConn) connect() error {
937 ac.mu.Lock()
938 if ac.state == connectivity.Shutdown {
939 ac.mu.Unlock()
942 if ac.state != connectivity.Idle {
943 ac.mu.Unlock()
946 ac.state = connectivity.Connecting
947 ac.cc.handleSubConnStateChange(ac.acbw, ac.state)
948 ac.mu.Unlock()
952 if err := ac.resetTransport(); err != nil {
953 grpclog.Warningf("Failed to dial %s: %v; please retry.", ac.addrs[0].Addr, err)
956 ac.tearDown(err)
960 ac.transportMonitor()
971 func (ac *addrConn) tryUpdateAddrs(addrs []resolver.Address) bool {
972 ac.mu.Lock()
973 defer ac.mu.Unlock()
974 grpclog.Infof("addrConn: tryUpdateAddrs curAddr: %v, addrs: %v", ac.curAddr, addrs)
975 if ac.state == connectivity.Shutdown {
976 ac.addrs = addrs
982 if reflect.DeepEqual(ac.curAddr, a) {
989 ac.addrs = addrs
990 ac.reconnectIdx = 0 // Start reconnecting from beginning in the new list.
1103 for ac := range conns {
1104 ac.tearDown(ErrClientConnClosing)
1153 func (ac *addrConn) adjustParams(r transport.GoAwayReason) {
1156 v := 2 * ac.dopts.copts.KeepaliveParams.Time
1157 ac.cc.mu.Lock()
1158 if v > ac.cc.mkp.Time {
1159 ac.cc.mkp.Time = v
1161 ac.cc.mu.Unlock()
1167 func (ac *addrConn) printf(format string, a ...interface{}) {
1168 if ac.events != nil {
1169 ac.events.Printf(format, a...)
1175 func (ac *addrConn) errorf(format string, a ...interface{}) {
1176 if ac.events != nil {
1177 ac.events.Errorf(format, a...)
1194 func (ac *addrConn) resetTransport() error {
1195 ac.mu.Lock()
1196 if ac.state == connectivity.Shutdown {
1197 ac.mu.Unlock()
1200 if ac.ready != nil {
1201 close(ac.ready)
1202 ac.ready = nil
1204 ac.transport = nil
1205 ridx := ac.reconnectIdx
1206 ac.mu.Unlock()
1207 ac.cc.mu.RLock()
1208 ac.dopts.copts.KeepaliveParams = ac.cc.mkp
1209 ac.cc.mu.RUnlock()
1212 ac.mu.Lock()
1213 if ac.backoffDeadline.IsZero() {
1217 backoffFor := ac.dopts.bs.Backoff(connectRetryNum) // time.Duration.
1230 connectRetryNum = ac.connectRetryNum
1231 backoffDeadline = ac.backoffDeadline
1232 connectDeadline = ac.connectDeadline
1233 ac.backoffDeadline = time.Time{}
1234 ac.connectDeadline = time.Time{}
1235 ac.connectRetryNum = 0
1237 if ac.state == connectivity.Shutdown {
1238 ac.mu.Unlock()
1241 ac.printf("connecting")
1242 if ac.state != connectivity.Connecting {
1243 ac.state = connectivity.Connecting
1244 ac.cc.handleSubConnStateChange(ac.acbw, ac.state)
1247 addrsIter := make([]resolver.Address, len(ac.addrs))
1248 copy(addrsIter, ac.addrs)
1249 copts := ac.dopts.copts
1250 ac.mu.Unlock()
1251 …connected, err := ac.createTransport(connectRetryNum, ridx, backoffDeadline, connectDeadline, addr…
1263 func (ac *addrConn) createTransport(connectRetryNum, ridx int, backoffDeadline, connectDeadline tim…
1269 Authority: ac.cc.authority,
1273 ac.mu.Lock()
1275 if !ac.backoffDeadline.IsZero() {
1281 ac.backoffDeadline = time.Time{}
1282 ac.connectDeadline = time.Time{}
1283 ac.connectRetryNum = 0
1285 ac.mu.Unlock()
1289 connectCtx, cancel := context.WithDeadline(ac.ctx, connectDeadline)
1291 copts.ChannelzParentID = ac.channelzID
1293 newTr, err := transport.NewClientTransport(connectCtx, ac.cc.ctx, target, copts, onPrefaceReceipt)
1296 ac.cc.blockingpicker.updateConnectionError(err)
1297 ac.mu.Lock()
1298 if ac.state == connectivity.Shutdown {
1300 ac.mu.Unlock()
1303 ac.mu.Unlock()
1307 if ac.dopts.waitForHandshake {
1315 case <-ac.ctx.Done():
1318 ac.mu.Lock()
1319 if ac.state == connectivity.Shutdown {
1320 ac.mu.Unlock()
1325 ac.printf("ready")
1326 ac.state = connectivity.Ready
1327 ac.cc.handleSubConnStateChange(ac.acbw, ac.state)
1328 ac.transport = newTr
1329 ac.curAddr = addr
1330 if ac.ready != nil {
1331 close(ac.ready)
1332 ac.ready = nil
1339 ac.connectRetryNum = connectRetryNum
1340 ac.backoffDeadline = backoffDeadline
1341 ac.connectDeadline = connectDeadline
1342 ac.reconnectIdx = i + 1 // Start reconnecting from the next backend in the list.
1344 ac.mu.Unlock()
1347 ac.mu.Lock()
1348 if ac.state == connectivity.Shutdown {
1349 ac.mu.Unlock()
1352 ac.state = connectivity.TransientFailure
1353 ac.cc.handleSubConnStateChange(ac.acbw, ac.state)
1354 ac.cc.resolveNow(resolver.ResolveNowOption{})
1355 if ac.ready != nil {
1356 close(ac.ready)
1357 ac.ready = nil
1359 ac.mu.Unlock()
1363 case <-ac.ctx.Done():
1365 return false, ac.ctx.Err()
1372 func (ac *addrConn) transportMonitor() {
1376 ac.mu.Lock()
1377 t := ac.transport
1378 if !ac.connectDeadline.IsZero() {
1379 timer = time.NewTimer(ac.connectDeadline.Sub(time.Now()))
1382 ac.mu.Unlock()
1401 ac.mu.Lock()
1403 if ac.backoffDeadline.IsZero() {
1404 ac.mu.Unlock()
1407 ac.mu.Unlock()
1421 ac.adjustParams(t.GetGoAwayReason())
1424 ac.mu.Lock()
1425 if ac.state == connectivity.Shutdown {
1426 ac.mu.Unlock()
1431 ac.state = connectivity.TransientFailure
1432 ac.cc.handleSubConnStateChange(ac.acbw, ac.state)
1433 ac.cc.resolveNow(resolver.ResolveNowOption{})
1434 ac.curAddr = resolver.Address{}
1435 ac.mu.Unlock()
1436 if err := ac.resetTransport(); err != nil {
1437 ac.mu.Lock()
1438 ac.printf("transport exiting: %v", err)
1439 ac.mu.Unlock()
1443 ac.tearDown(err)
1452 func (ac *addrConn) wait(ctx context.Context, hasBalancer, failfast bool) (transport.ClientTranspor…
1454 ac.mu.Lock()
1456 case ac.state == connectivity.Shutdown:
1459 err := ac.tearDownErr
1460 ac.mu.Unlock()
1463 ac.mu.Unlock()
1465 case ac.state == connectivity.Ready:
1466 ct := ac.transport
1467 ac.mu.Unlock()
1469 case ac.state == connectivity.TransientFailure:
1471 ac.mu.Unlock()
1475 ready := ac.ready
1478 ac.ready = ready
1480 ac.mu.Unlock()
1493 func (ac *addrConn) getReadyTransport() (transport.ClientTransport, bool) {
1494 ac.mu.Lock()
1495 if ac.state == connectivity.Ready {
1496 t := ac.transport
1497 ac.mu.Unlock()
1501 if ac.state == connectivity.Idle {
1504 ac.mu.Unlock()
1507 ac.connect()
1517 func (ac *addrConn) tearDown(err error) {
1518 ac.cancel()
1519 ac.mu.Lock()
1520 defer ac.mu.Unlock()
1521 if ac.state == connectivity.Shutdown {
1524 ac.curAddr = resolver.Address{}
1525 if err == errConnDrain && ac.transport != nil {
1530 ac.transport.GracefulClose()
1532 ac.state = connectivity.Shutdown
1533 ac.tearDownErr = err
1534 ac.cc.handleSubConnStateChange(ac.acbw, ac.state)
1535 if ac.events != nil {
1536 ac.events.Finish()
1537 ac.events = nil
1539 if ac.ready != nil {
1540 close(ac.ready)
1541 ac.ready = nil
1544 channelz.RemoveEntry(ac.channelzID)
1548 func (ac *addrConn) getState() connectivity.State {
1549 ac.mu.Lock()
1550 defer ac.mu.Unlock()
1551 return ac.state
1554 func (ac *addrConn) getCurAddr() (ret resolver.Address) {
1555 ac.mu.Lock()
1556 ret = ac.curAddr
1557 ac.mu.Unlock()
1561 func (ac *addrConn) ChannelzMetric() *channelz.ChannelInternalMetric {
1562 ac.mu.Lock()
1563 addr := ac.curAddr.Addr
1564 ac.mu.Unlock()
1565 state := ac.getState()
1566 ac.czmu.RLock()
1567 defer ac.czmu.RUnlock()
1571 CallsStarted: ac.callsStarted,
1572 CallsSucceeded: ac.callsSucceeded,
1573 CallsFailed: ac.callsFailed,
1574 LastCallStartedTimestamp: ac.lastCallStartedTime,
1578 func (ac *addrConn) incrCallsStarted() {
1579 ac.czmu.Lock()
1580 ac.callsStarted++
1581 ac.lastCallStartedTime = time.Now()
1582 ac.czmu.Unlock()
1585 func (ac *addrConn) incrCallsSucceeded() {
1586 ac.czmu.Lock()
1587 ac.callsSucceeded++
1588 ac.czmu.Unlock()
1591 func (ac *addrConn) incrCallsFailed() {
1592 ac.czmu.Lock()
1593 ac.callsFailed++
1594 ac.czmu.Unlock()