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

Method newAddrConnLocked

clientconn.go:903–935  ·  view source on GitHub ↗

newAddrConnLocked creates an addrConn for addrs and adds it to cc.conns. Caller needs to make sure len(addrs) > 0.

(addrs []resolver.Address, opts balancer.NewSubConnOptions)

Source from the content-addressed store, hash-verified

901//
902// Caller needs to make sure len(addrs) > 0.
903func (cc *ClientConn) newAddrConnLocked(addrs []resolver.Address, opts balancer.NewSubConnOptions) (*addrConn, error) {
904 if cc.conns == nil {
905 return nil, ErrClientConnClosing
906 }
907
908 ac := &addrConn{
909 state: connectivity.Idle,
910 cc: cc,
911 addrs: copyAddresses(addrs),
912 scopts: opts,
913 dopts: cc.dopts,
914 channelz: channelz.RegisterSubChannel(cc.channelz, ""),
915 resetBackoff: make(chan struct{}),
916 }
917 ac.updateTelemetryLabelsLocked()
918 ac.ctx, ac.cancel = context.WithCancel(cc.ctx)
919 // Start with our address set to the first address; this may be updated if
920 // we connect to different addresses.
921 ac.channelz.ChannelMetrics.Target.Store(&addrs[0].Addr)
922
923 channelz.AddTraceEvent(logger, ac.channelz, 0, &channelz.TraceEvent{
924 Desc: "Subchannel created",
925 Severity: channelz.CtInfo,
926 Parent: &channelz.TraceEvent{
927 Desc: fmt.Sprintf("Subchannel(id:%d) created", ac.channelz.ID),
928 Severity: channelz.CtInfo,
929 },
930 })
931
932 // Track ac in cc. This needs to be done before any getTransport(...) is called.
933 cc.conns[ac] = struct{}{}
934 return ac, nil
935}
936
937// removeAddrConn removes the addrConn in the subConn from clientConn.
938// It also tears down the ac with the given error.

Callers 1

NewSubConnMethod · 0.80

Calls 4

RegisterSubChannelFunction · 0.92
AddTraceEventFunction · 0.92
copyAddressesFunction · 0.85

Tested by

no test coverage detected