Skip to content

Commit e711909

Browse files
committed
Only wait for 5 seconds to report lifecycle at end
1 parent 292a878 commit e711909

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

agent/agent.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,18 +1364,28 @@ func (a *agent) Close() error {
13641364
// Set final state and wait for it to be reported because context
13651365
// cancellation will stop the report loop.
13661366
a.setLifecycle(ctx, lifecycleState)
1367-
// TODO(mafredri): What if the agent token is revoked, build outdated, etc.?
1368-
for s := range a.lifecycleReported {
1369-
if s == lifecycleState {
1370-
break
1371-
}
1372-
}
13731367

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

1373+
// Wait for the lifecycle to be reported, but don't wait forever so
1374+
// that we don't break user expectations.
1375+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
1376+
defer cancel()
1377+
lifecycleWaitLoop:
1378+
for {
1379+
select {
1380+
case <-ctx.Done():
1381+
break lifecycleWaitLoop
1382+
case s := <-a.lifecycleReported:
1383+
if s == lifecycleState {
1384+
break lifecycleWaitLoop
1385+
}
1386+
}
1387+
}
1388+
13791389
close(a.closed)
13801390
a.closeCancel()
13811391
_ = a.sshServer.Close()

0 commit comments

Comments
 (0)