Skip to content

Commit 20d09ab

Browse files
authored
fix: backoff retry and timeouts in HNS restart (#3540)
fix: backoff retry and timeouts in HNS restart Signed-off-by: Evan Baker <[email protected]>
1 parent 58b53d0 commit 20d09ab

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: platform/os_windows.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,15 @@ func restartHNS(ctx context.Context) error {
308308
tryStopServiceFn(ctx, service),
309309
retry.UntilSucceeded(),
310310
retry.Context(ctx),
311+
retry.DelayType(retry.BackOffDelay),
311312
)
312313
// Start the service again
313314
log.Printf("Starting HNS service")
314315
_ = retry.Do(
315316
tryStartServiceFn(ctx, service),
316317
retry.UntilSucceeded(),
317318
retry.Context(ctx),
319+
retry.DelayType(retry.BackOffDelay),
318320
)
319321
log.Printf("HNS service started")
320322
return nil
@@ -342,6 +344,8 @@ func tryStartServiceFn(ctx context.Context, service managedService) func() error
342344
}
343345
}
344346
// Wait for the service to start
347+
deadline, cancel := context.WithTimeout(ctx, 90*time.Second)
348+
defer cancel()
345349
ticker := time.NewTicker(500 * time.Millisecond) //nolint:gomnd // 500ms
346350
defer ticker.Stop()
347351
for {
@@ -354,8 +358,8 @@ func tryStartServiceFn(ctx context.Context, service managedService) func() error
354358
break
355359
}
356360
select {
357-
case <-ctx.Done():
358-
return errors.Wrap(ctx.Err(), "context cancelled")
361+
case <-deadline.Done():
362+
return deadline.Err() //nolint:wrapcheck // error has sufficient context
359363
case <-ticker.C:
360364
}
361365
}
@@ -379,6 +383,8 @@ func tryStopServiceFn(ctx context.Context, service managedService) func() error
379383
}
380384
}
381385
// Wait for the service to stop
386+
deadline, cancel := context.WithTimeout(ctx, 90*time.Second)
387+
defer cancel()
382388
ticker := time.NewTicker(500 * time.Millisecond) //nolint:gomnd // 500ms
383389
defer ticker.Stop()
384390
for {
@@ -391,8 +397,8 @@ func tryStopServiceFn(ctx context.Context, service managedService) func() error
391397
break
392398
}
393399
select {
394-
case <-ctx.Done():
395-
return errors.Wrap(ctx.Err(), "context cancelled")
400+
case <-deadline.Done():
401+
return deadline.Err() //nolint:wrapcheck // error has sufficient context
396402
case <-ticker.C:
397403
}
398404
}

0 commit comments

Comments
 (0)