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

Method updateConnectivityState

clientconn.go:1279–1308  ·  view source on GitHub ↗

Note: this requires a lock on ac.mu.

(s connectivity.State, lastErr error)

Source from the content-addressed store, hash-verified

1277
1278// Note: this requires a lock on ac.mu.
1279func (ac *addrConn) updateConnectivityState(s connectivity.State, lastErr error) {
1280 if ac.state == s {
1281 return
1282 }
1283
1284 // If we are transitioning out of Ready, it means there is a disconnection.
1285 // A SubConn can also transition from CONNECTING directly to IDLE when
1286 // a transport is successfully created, but the connection fails
1287 // before the SubConn can send the notification for READY. We treat
1288 // this as a successful connection and transition to IDLE.
1289 // TODO: https://github.com/grpc/grpc-go/issues/7862 - Remove the second
1290 // part of the if condition below once the issue is fixed.
1291 if ac.state == connectivity.Ready || (ac.state == connectivity.Connecting && s == connectivity.Idle) {
1292 disconnectError := ac.disconnectErrorLabel
1293 if disconnectError == "" {
1294 disconnectError = "unknown"
1295 }
1296 disconnectionsMetric.Record(ac.cc.metricsRecorderList, 1, ac.cc.target, ac.backendServiceLabel, ac.localityLabel, disconnectError)
1297 openConnectionsMetric.Record(ac.cc.metricsRecorderList, -1, ac.cc.target, ac.backendServiceLabel, ac.securityLevelLocked(), ac.localityLabel)
1298 }
1299 ac.disconnectErrorLabel = "" // Reset for next time
1300 ac.state = s
1301 ac.channelz.ChannelMetrics.State.Store(&s)
1302 if lastErr == nil {
1303 channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v", s)
1304 } else {
1305 channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v, last error: %s", s, lastErr)
1306 }
1307 ac.acbw.updateState(s, lastErr)
1308}
1309
1310// adjustParams updates parameters used to create transports upon
1311// receiving a GoAway.

Callers 5

updateAddrsMethod · 0.95
createTransportMethod · 0.95
startHealthCheckMethod · 0.95
tearDownMethod · 0.95

Calls 4

securityLevelLockedMethod · 0.95
InfofFunction · 0.92
RecordMethod · 0.45
updateStateMethod · 0.45

Tested by

no test coverage detected