Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only wait for 5 seconds to report lifecycle at end
  • Loading branch information
mafredri committed Mar 6, 2023
commit e711909013be45e7b2f738da44b40e40324d8789
22 changes: 16 additions & 6 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,18 +1364,28 @@ func (a *agent) Close() error {
// Set final state and wait for it to be reported because context
// cancellation will stop the report loop.
a.setLifecycle(ctx, lifecycleState)
// TODO(mafredri): What if the agent token is revoked, build outdated, etc.?
for s := range a.lifecycleReported {
if s == lifecycleState {
break
}
}

if lifecycleState != codersdk.WorkspaceAgentLifecycleOff {
// TODO(mafredri): Delay shutdown, ensure debugging is possible.
_ = false
}

// Wait for the lifecycle to be reported, but don't wait forever so
// that we don't break user expectations.
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
lifecycleWaitLoop:
for {
select {
case <-ctx.Done():
break lifecycleWaitLoop
case s := <-a.lifecycleReported:
if s == lifecycleState {
break lifecycleWaitLoop
}
}
}

close(a.closed)
a.closeCancel()
_ = a.sshServer.Close()
Expand Down