Skip to content

Commit a44bfa4

Browse files
authored
small adjustment to the timer behavior in the httpcluster retry loop (#85)
1 parent 4ba1cb4 commit a44bfa4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

runnables/httpcluster/runner.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,17 @@ func (r *Runner) waitForIsRunning(
130130
) bool {
131131
ctx, cancel := context.WithTimeout(ctx, timeout)
132132
defer cancel()
133-
initialRetry := 5 * time.Millisecond
133+
retryDelay := 5 * time.Millisecond
134134
maxRetry := 1 * time.Second
135135

136+
timer := time.NewTimer(retryDelay)
137+
defer timer.Stop()
138+
136139
for {
137140
select {
138141
case <-ctx.Done():
139142
return false
140-
case <-time.After(initialRetry):
143+
case <-timer.C:
141144
if server.IsRunning() {
142145
return true
143146
}
@@ -147,8 +150,8 @@ func (r *Runner) waitForIsRunning(
147150
return false
148151
}
149152

150-
// Exponentially increase the backoff delay
151-
initialRetry = min(time.Duration(float64(initialRetry)*1.5), maxRetry)
153+
retryDelay = min(time.Duration(float64(retryDelay)*1.5), maxRetry)
154+
timer.Reset(retryDelay)
152155
}
153156
}
154157
}

0 commit comments

Comments
 (0)