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

Method ensureAgent

coderd/tailnet.go:420–445  ·  view source on GitHub ↗
(agentID uuid.UUID)

Source from the content-addressed store, hash-verified

418}
419
420func (m *MultiAgentController) ensureAgent(agentID uuid.UUID) error {
421 m.mu.Lock()
422 defer m.mu.Unlock()
423
424 _, ok := m.connectionTimes[agentID]
425 // If we don't have the agent, subscribe.
426 if !ok {
427 m.logger.Debug(context.Background(),
428 "subscribing to agent", slog.F("agent_id", agentID))
429 if m.coordination != nil {
430 err := m.coordination.SendRequest(&proto.CoordinateRequest{
431 AddTunnel: &proto.CoordinateRequest_Tunnel{Id: agentID[:]},
432 })
433 if err != nil {
434 err = xerrors.Errorf("subscribe agent: %w", err)
435 m.coordination.SendErr(err)
436 _ = m.coordination.CloseClient()
437 m.coordination = nil
438 return err
439 }
440 }
441 m.tickets[agentID] = map[uuid.UUID]struct{}{}
442 }
443 m.connectionTimes[agentID] = time.Now()
444 return nil
445}
446
447func (m *MultiAgentController) acquireTicket(agentID uuid.UUID) (release func()) {
448 id := uuid.New()

Callers 1

AgentConnMethod · 0.80

Calls 6

SendRequestMethod · 0.80
SendErrMethod · 0.80
CloseClientMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected