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

Method waitForReconnection

cli/cliui/agent.go:330–350  ·  view source on GitHub ↗

waitForReconnection handles the Disconnected state. Returns when agent reconnects along with whether to show startup logs.

(ctx context.Context, agent codersdk.WorkspaceAgent)

Source from the content-addressed store, hash-verified

328// waitForReconnection handles the Disconnected state.
329// Returns when agent reconnects along with whether to show startup logs.
330func (aw *agentWaiter) waitForReconnection(ctx context.Context, agent codersdk.WorkspaceAgent) (codersdk.WorkspaceAgent, bool, error) {
331 // If the agent was still starting during disconnect, we'll
332 // show startup logs.
333 showStartupLogs := agent.LifecycleState.Starting()
334
335 stage := "The workspace agent lost connection"
336 aw.sw.Start(stage)
337 aw.sw.Log(time.Now(), codersdk.LogLevelWarn, "Wait for it to reconnect or restart your workspace.")
338 aw.sw.Log(time.Now(), codersdk.LogLevelWarn, troubleshootingMessage(agent, fmt.Sprintf("%s/admin/templates/troubleshooting#agent-connection-issues", aw.opts.DocsURL)))
339
340 disconnectedAt := agent.DisconnectedAt
341 agent, err := aw.pollWhile(ctx, agent, func(agent codersdk.WorkspaceAgent) bool {
342 return agent.Status == codersdk.WorkspaceAgentDisconnected
343 })
344 if err != nil {
345 return agent, showStartupLogs, err
346 }
347 aw.sw.Complete(stage, safeDuration(aw.sw, agent.LastConnectedAt, disconnectedAt))
348
349 return agent, showStartupLogs, nil
350}
351
352// pollWhile polls the agent while the condition is true. It fetches the agent
353// on each iteration and returns the updated agent when the condition is false,

Callers 1

waitMethod · 0.95

Calls 7

pollWhileMethod · 0.95
troubleshootingMessageFunction · 0.85
safeDurationFunction · 0.85
LogMethod · 0.80
StartMethod · 0.65
StartingMethod · 0.45
CompleteMethod · 0.45

Tested by

no test coverage detected