waitForReconnection handles the Disconnected state. Returns when agent reconnects along with whether to show startup logs.
(ctx context.Context, agent codersdk.WorkspaceAgent)
| 328 | // waitForReconnection handles the Disconnected state. |
| 329 | // Returns when agent reconnects along with whether to show startup logs. |
| 330 | func (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, |
no test coverage detected