fix(lifecycle): make agentctl health retry delay cancelable

Replace `time.Sleep(retryDelay)` in `waitForHealth` (container.go) and
`waitForAgentctlHealthWith` (executor_docker.go) with a cancelable
`select { <-ctx.Done() | <-time.After(retryDelay) }`. Also skip the
final retry's sleep — the loop only re-enters when `i+1 < maxRetries`,
so the extra delay was just added latency on aborted launches.

Cancellation now propagates within ≤500 ms instead of waiting for the
next probe iteration to observe `ctx.Err()`.
This commit is contained in:
José Almeida
2026-05-11 23:53:41 +01:00
parent 17e4a1b2fe
commit aaec9e878a
2 changed files with 17 additions and 2 deletions
@@ -270,7 +270,16 @@ func (cm *ContainerManager) waitForHealth(ctx context.Context, ctl *agentctl.Con
if ctx.Err() != nil {
return ctx.Err()
}
time.Sleep(retryDelay)
// Cancelable wait that also skips the final retry's sleep — the loop
// only re-enters if i+1 < maxRetries, so the extra delay was just
// added latency on aborted launches.
if i+1 < maxRetries {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(retryDelay):
}
}
}
if lastErr != nil {
@@ -495,7 +495,13 @@ func waitForAgentctlHealthWith(ctx context.Context, ctl healthChecker, maxRetrie
if ctx.Err() != nil {
return ctx.Err()
}
time.Sleep(retryDelay)
if i+1 < maxRetries {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(retryDelay):
}
}
}
if lastErr != nil {