File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -1364,18 +1364,28 @@ func (a *agent) Close() error {
1364
1364
// Set final state and wait for it to be reported because context
1365
1365
// cancellation will stop the report loop.
1366
1366
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
- }
1373
1367
1374
1368
if lifecycleState != codersdk .WorkspaceAgentLifecycleOff {
1375
1369
// TODO(mafredri): Delay shutdown, ensure debugging is possible.
1376
1370
_ = false
1377
1371
}
1378
1372
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
+
1379
1389
close (a .closed )
1380
1390
a .closeCancel ()
1381
1391
_ = a .sshServer .Close ()
You can’t perform that action at this time.
0 commit comments