MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / Run

Method Run

supervisor/supervisor.go:112–200  ·  view source on GitHub ↗
(
	ctx context.Context,
	connectedSignal *signal.Signal,
)

Source from the content-addressed store, hash-verified

110}
111
112func (s *Supervisor) Run(
113 ctx context.Context,
114 connectedSignal *signal.Signal,
115) error {
116 if s.config.ICMPRouterServer != nil {
117 go func() {
118 if err := s.config.ICMPRouterServer.Serve(ctx); err != nil {
119 if errors.Is(err, net.ErrClosed) {
120 s.log.Logger().Info().Err(err).Msg("icmp router terminated")
121 } else {
122 s.log.Logger().Err(err).Msg("icmp router terminated")
123 }
124 }
125 }()
126 }
127
128 // Setup DNS Resolver refresh
129 go s.config.OriginDNSService.StartRefreshLoop(ctx)
130
131 if err := s.initialize(ctx, connectedSignal); err != nil {
132 if err == errEarlyShutdown {
133 return nil
134 }
135 s.log.Logger().Error().Err(err).Msg("initial tunnel connection failed")
136 return err
137 }
138 var tunnelsWaiting []int
139 tunnelsActive := s.config.HAConnections
140
141 backoff := retry.NewBackoff(s.config.Retries, tunnelRetryDuration, true)
142 var backoffTimer <-chan time.Time
143
144 shuttingDown := false
145 for {
146 select {
147 // Context cancelled
148 case <-ctx.Done():
149 for tunnelsActive > 0 {
150 <-s.tunnelErrors
151 tunnelsActive--
152 }
153 return nil
154 // startTunnel completed with a response
155 // (note that this may also be caused by context cancellation)
156 case tunnelError := <-s.tunnelErrors:
157 tunnelsActive--
158 s.log.ConnAwareLogger().Err(tunnelError.err).Int(connection.LogFieldConnIndex, tunnelError.index).Msg("Connection terminated")
159 if tunnelError.err != nil && !shuttingDown {
160 switch tunnelError.err.(type) {
161 case ReconnectSignal:
162 // For tunnels that closed with reconnect signal, we reconnect immediately
163 go s.startTunnel(ctx, tunnelError.index, s.newConnectedTunnelSignal(tunnelError.index))
164 tunnelsActive++
165 continue
166 }
167 // Make sure we don't continue if there is no more fallback allowed
168 if _, retry := s.tunnelsProtocolFallback[tunnelError.index].GetMaxBackoffDuration(ctx); !retry {
169 continue

Callers 1

StartTunnelDaemonFunction · 0.95

Calls 15

initializeMethod · 0.95
startTunnelMethod · 0.95
waitForNextTunnelMethod · 0.95
NewBackoffFunction · 0.92
IsMethod · 0.80
LoggerMethod · 0.80
StartRefreshLoopMethod · 0.80
IntMethod · 0.80
ConnAwareLoggerMethod · 0.80
GetMaxBackoffDurationMethod · 0.80
BackoffTimerMethod · 0.80

Tested by

no test coverage detected