File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
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,10 +289,10 @@ 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
@@ -295,24 +304,23 @@ func (a *agent) runCoordinator(ctx context.Context) {
295
304
}
296
305
select {
297
306
case <- ctx .Done ():
298
- return
307
+ return false
299
308
default :
300
309
}
301
310
sendNodes , errChan := tailnet .ServeCoordinator (coordinator , a .network .UpdateNodes )
302
311
a .network .SetNodeCallback (sendNodes )
303
312
select {
304
313
case <- ctx .Done ():
305
- return
314
+ return false
306
315
case err := <- errChan :
307
316
if a .isClosed () {
308
- return
317
+ return false
309
318
}
310
319
if errors .Is (err , context .Canceled ) {
311
- return
320
+ return false
312
321
}
313
322
a .logger .Debug (ctx , "node broker accept exited; restarting connection" , slog .Error (err ))
314
- a .runCoordinator (ctx )
315
- return
323
+ return true
316
324
}
317
325
}
318
326
You can’t perform that action at this time.
0 commit comments