startTailnetAPI starts a routine that uses the Tailnet API. c.f. startAgentAPI which is the same but for the Agent API.
( name string, behavior gracefulShutdownBehavior, f func(context.Context, tailnetproto.DRPCTailnetClient24) error, )
| 2469 | // startTailnetAPI starts a routine that uses the Tailnet API. c.f. startAgentAPI which is the same |
| 2470 | // but for the Agent API. |
| 2471 | func (a *apiConnRoutineManager) startTailnetAPI( |
| 2472 | name string, behavior gracefulShutdownBehavior, |
| 2473 | f func(context.Context, tailnetproto.DRPCTailnetClient24) error, |
| 2474 | ) { |
| 2475 | logger := a.logger.With(slog.F("name", name)) |
| 2476 | var ctx context.Context |
| 2477 | switch behavior { |
| 2478 | case gracefulShutdownBehaviorStop: |
| 2479 | ctx = a.stopCtx |
| 2480 | case gracefulShutdownBehaviorRemain: |
| 2481 | ctx = a.remainCtx |
| 2482 | default: |
| 2483 | panic("unknown behavior") |
| 2484 | } |
| 2485 | a.eg.Go(func() error { |
| 2486 | logger.Debug(ctx, "starting tailnet routine") |
| 2487 | err := f(ctx, a.tAPI) |
| 2488 | err = shouldPropagateError(ctx, logger, err) |
| 2489 | logger.Debug(ctx, "routine exited", slog.Error(err)) |
| 2490 | if err != nil { |
| 2491 | return xerrors.Errorf("error in routine %s: %w", name, err) |
| 2492 | } |
| 2493 | return nil |
| 2494 | }) |
| 2495 | } |
| 2496 | |
| 2497 | // shouldPropagateError decides whether an error from an API connection routine should be propagated to the |
| 2498 | // apiConnRoutineManager. Its purpose is to prevent errors related to shutting down from propagating to the manager's |
no test coverage detected