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 @@ -1269,18 +1269,28 @@ func (a *agent) Close() error {
1269
1269
// Set final state and wait for it to be reported because context
1270
1270
// cancellation will stop the report loop.
1271
1271
a .setLifecycle (ctx , lifecycleState )
1272
- // TODO(mafredri): What if the agent token is revoked, build outdated, etc.?
1273
- for s := range a .lifecycleReported {
1274
- if s == lifecycleState {
1275
- break
1276
- }
1277
- }
1278
1272
1279
1273
if lifecycleState != codersdk .WorkspaceAgentLifecycleOff {
1280
1274
// TODO(mafredri): Delay shutdown, ensure debugging is possible.
1281
1275
_ = false
1282
1276
}
1283
1277
1278
+ // Wait for the lifecycle to be reported, but don't wait forever so
1279
+ // that we don't break user expectations.
1280
+ ctx , cancel := context .WithTimeout (ctx , 5 * time .Second )
1281
+ defer cancel ()
1282
+ lifecycleWaitLoop:
1283
+ for {
1284
+ select {
1285
+ case <- ctx .Done ():
1286
+ break lifecycleWaitLoop
1287
+ case s := <- a .lifecycleReported :
1288
+ if s == lifecycleState {
1289
+ break lifecycleWaitLoop
1290
+ }
1291
+ }
1292
+ }
1293
+
1284
1294
close (a .closed )
1285
1295
a .closeCancel ()
1286
1296
_ = a .sshServer .Close ()
You can’t perform that action at this time.
0 commit comments