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