Skip to content

Commit a94dc79

Browse files
authored
Merge pull request #6434 from oasisprotocol/peternose/trivial/limit-runtime-restarts
go/runtime/host/sandbox/host: Limit runtime restarts
2 parents a5d4e04 + 954bfc4 commit a94dc79

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

.changelog/6434.trivial.md

Whitespace-only changes.

go/common/backoff/backoff.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import "github.com/cenkalti/backoff/v4"
55

66
// NewExponentialBackOff creates an instance of ExponentialBackOff using reasonable defaults.
77
func NewExponentialBackOff() *backoff.ExponentialBackOff {
8-
boff := backoff.NewExponentialBackOff()
9-
boff.MaxElapsedTime = 0 // Make sure that the backoff never stops by default.
10-
return boff
8+
return backoff.NewExponentialBackOff(
9+
// Make sure that the backoff never stops by default.
10+
backoff.WithMaxElapsedTime(0),
11+
)
1112
}

go/runtime/host/sandbox/host.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import (
2626
var errRuntimeNotReady = errors.New("runtime is not yet ready")
2727

2828
const (
29-
runtimeInitTimeout = 1 * time.Second
30-
runtimeExtendedInitTimeout = 120 * time.Second
31-
runtimeInterruptTimeout = 1 * time.Second
29+
runtimeInitTimeout = time.Second
30+
runtimeExtendedInitTimeout = 2 * time.Minute
31+
runtimeInterruptTimeout = time.Second
3232
stopTickerTimeout = 15 * time.Minute
3333
watchdogInterval = 15 * time.Second
3434
watchdogPingTimeout = 5 * time.Second
35+
restartMaxInterval = time.Hour
36+
restartMaxElapsedTime = 24 * time.Hour
3537

3638
ctrlChannelBufferSize = 16
3739
)
@@ -473,7 +475,10 @@ func (h *sandboxHost) manager(ctx context.Context) {
473475
// Initialize a ticker for restarting the process. We use a separate channel
474476
// to restart the process immediately on the first run, as we don't want to wait
475477
// for the first tick.
476-
ticker = backoff.NewTicker(cmnBackoff.NewExponentialBackOff())
478+
ticker = backoff.NewTicker(backoff.NewExponentialBackOff(
479+
backoff.WithMaxInterval(restartMaxInterval),
480+
backoff.WithMaxElapsedTime(restartMaxElapsedTime),
481+
))
477482
firstTickCh <- struct{}{}
478483
attempt = 0
479484
}
@@ -483,7 +488,11 @@ func (h *sandboxHost) manager(ctx context.Context) {
483488
h.logger.Warn("termination requested")
484489
return
485490
case <-firstTickCh:
486-
case <-ticker.C:
491+
case _, ok := <-ticker.C:
492+
if !ok {
493+
h.logger.Warn("restart ticker stopped")
494+
return
495+
}
487496
}
488497

489498
attempt++
@@ -494,6 +503,7 @@ func (h *sandboxHost) manager(ctx context.Context) {
494503
if err := h.startProcess(ctx); err != nil {
495504
h.logger.Error("failed to start runtime",
496505
"err", err,
506+
"attempt", attempt,
497507
)
498508

499509
// Notify subscribers that a runtime has failed to start.

0 commit comments

Comments
 (0)