Skip to content

Commit aa68796

Browse files
committed
Fix startup timeout msg
1 parent f2f69bb commit aa68796

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

agent/agentscripts/agentscripts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestTimeout(t *testing.T) {
4646
runner := setup(t, nil)
4747
defer runner.Close()
4848
err := runner.Init([]codersdk.WorkspaceAgentScript{{
49-
Script: "sleep 3",
49+
Script: "sleep infinity",
5050
Timeout: time.Millisecond,
5151
}})
5252
require.NoError(t, err)

cli/cliui/agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
201201
switch agent.LifecycleState {
202202
case codersdk.WorkspaceAgentLifecycleReady:
203203
sw.Complete(stage, agent.ReadyAt.Sub(*agent.StartedAt))
204+
case codersdk.WorkspaceAgentLifecycleStartTimeout:
205+
sw.Fail(stage, 0)
206+
sw.Log(time.Time{}, codersdk.LogLevelWarn, "Warning: A startup script timed out and your workspace may be incomplete.")
204207
case codersdk.WorkspaceAgentLifecycleStartError:
205208
sw.Fail(stage, agent.ReadyAt.Sub(*agent.StartedAt))
206209
// Use zero time (omitted) to separate these from the startup logs.

cli/cliui/agent_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ func TestAgent(t *testing.T) {
5757
"For more information and troubleshooting, see",
5858
},
5959
},
60+
{
61+
name: "Start timeout",
62+
opts: cliui.AgentOptions{
63+
FetchInterval: time.Millisecond,
64+
},
65+
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentLog) error{
66+
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentLog) error {
67+
agent.Status = codersdk.WorkspaceAgentConnecting
68+
return nil
69+
},
70+
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentLog) error {
71+
agent.Status = codersdk.WorkspaceAgentConnected
72+
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleStartTimeout
73+
agent.FirstConnectedAt = ptr.Ref(time.Now())
74+
return nil
75+
},
76+
},
77+
want: []string{
78+
"⧗ Waiting for the workspace agent to connect",
79+
"✔ Waiting for the workspace agent to connect",
80+
"⧗ Running workspace agent startup scripts (non-blocking)",
81+
"✘ Running workspace agent startup scripts (non-blocking)",
82+
"Warning: A startup script timed out and your workspace may be incomplete.",
83+
},
84+
},
6085
{
6186
name: "Initial connection timeout",
6287
opts: cliui.AgentOptions{

codersdk/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const (
5858
// Starting returns true if the agent is in the process of starting.
5959
func (l WorkspaceAgentLifecycle) Starting() bool {
6060
switch l {
61-
case WorkspaceAgentLifecycleCreated, WorkspaceAgentLifecycleStarting, WorkspaceAgentLifecycleStartTimeout:
61+
case WorkspaceAgentLifecycleCreated, WorkspaceAgentLifecycleStarting:
6262
return true
6363
default:
6464
return false

provisioner/terraform/resources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
547547
if resource.Mode == tfjson.DataResourceMode {
548548
continue
549549
}
550-
if resource.Type == "coder_agent" || resource.Type == "coder_agent_instance" || resource.Type == "coder_app" || resource.Type == "coder_metadata" {
550+
if resource.Type == "coder_script" || resource.Type == "coder_agent" || resource.Type == "coder_agent_instance" || resource.Type == "coder_app" || resource.Type == "coder_metadata" {
551551
continue
552552
}
553553
label := convertAddressToLabel(resource.Address)

0 commit comments

Comments
 (0)