File tree 1 file changed +18
-9
lines changed
1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -272,6 +272,15 @@ func (a *agent) runTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) {
272
272
273
273
// runCoordinator listens for nodes and updates the self-node as it changes.
274
274
func (a * agent ) runCoordinator (ctx context.Context ) {
275
+ for {
276
+ reconnect := a .runCoordinatorWithRetry (ctx )
277
+ if ! reconnect {
278
+ return
279
+ }
280
+ }
281
+ }
282
+
283
+ func (a * agent ) runCoordinatorWithRetry (ctx context.Context ) (reconnect bool ) {
275
284
var coordinator net.Conn
276
285
var err error
277
286
// An exponential back-off occurs when the connection is failing to dial.
@@ -280,38 +289,38 @@ func (a *agent) runCoordinator(ctx context.Context) {
280
289
coordinator , err = a .coordinatorDialer (ctx )
281
290
if err != nil {
282
291
if errors .Is (err , context .Canceled ) {
283
- return
292
+ return false
284
293
}
285
294
if a .isClosed () {
286
- return
295
+ return false
287
296
}
288
297
a .logger .Warn (context .Background (), "failed to dial" , slog .Error (err ))
289
298
continue
290
299
}
300
+ //nolint:revive // Defer is ok because we're exiting this loop.
301
+ defer coordinator .Close ()
291
302
a .logger .Info (context .Background (), "connected to coordination server" )
292
303
break
293
304
}
294
305
select {
295
306
case <- ctx .Done ():
296
- return
307
+ return false
297
308
default :
298
309
}
299
- defer coordinator .Close ()
300
310
sendNodes , errChan := tailnet .ServeCoordinator (coordinator , a .network .UpdateNodes )
301
311
a .network .SetNodeCallback (sendNodes )
302
312
select {
303
313
case <- ctx .Done ():
304
- return
314
+ return false
305
315
case err := <- errChan :
306
316
if a .isClosed () {
307
- return
317
+ return false
308
318
}
309
319
if errors .Is (err , context .Canceled ) {
310
- return
320
+ return false
311
321
}
312
322
a .logger .Debug (ctx , "node broker accept exited; restarting connection" , slog .Error (err ))
313
- a .runCoordinator (ctx )
314
- return
323
+ return true
315
324
}
316
325
}
317
326
You can’t perform that action at this time.
0 commit comments