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