Skip to content

Commit

Permalink
mantle/util/retry: add more debug statements to retry function
Browse files Browse the repository at this point in the history
- Print a little more information about the errors that are encountered
  on each try.
- Print out the amount of time remaining until the timeout occurs.
  • Loading branch information
dustymabe committed Sep 4, 2024
1 parent 30480db commit a42c24d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mantle/util/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func RetryConditional(attempts int, delay time.Duration, shouldRetry func(err er
// between each try based on the given delay.
func RetryUntilTimeout(timeout, delay time.Duration, f func() error) error {
after := time.After(timeout)
deadline := time.Now().Add(timeout)
for {
select {
case <-after:
Expand All @@ -63,9 +64,11 @@ func RetryUntilTimeout(timeout, delay time.Duration, f func() error) error {
// how long it takes remote network requests to finish.
start := time.Now()
err := f()
plog.Debugf("RetryUntilTimeout: f() took %v", time.Since(start))
plog.Debugf("RetryUntilTimeout: f() took %v. %v until timeout.", time.Since(start), time.Until(deadline).Round(time.Second))
if err == nil {
break
} else {
plog.Debugf("RetryUntilTimeout: f() returned error: %s", err)
}
time.Sleep(delay)
}
Expand Down

0 comments on commit a42c24d

Please sign in to comment.