MCPcopy Index your code
hub / github.com/coder/coder / startTailnetAPI

Method startTailnetAPI

agent/agent.go:2471–2495  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

2469// startTailnetAPI starts a routine that uses the Tailnet API. c.f. startAgentAPI which is the same
2470// but for the Agent API.
2471func (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

Callers 1

runMethod · 0.80

Calls 4

shouldPropagateErrorFunction · 0.85
GoMethod · 0.80
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected