Skip to content

Commit 4c1d856

Browse files
committed
Relax retry heuristics
Even if we didn't make much progress, allow one retry per minute anyway. Notably this allows one retry ~immediately, we see failures a few dozen milliseconds after the connection is set up. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent 3f12dc9 commit 4c1d856

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

docker/body_reader.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ import (
1717
"github.com/sirupsen/logrus"
1818
)
1919

20-
// bodyReaderMinimumProgress is the minimum progress we want to see before we retry
21-
const bodyReaderMinimumProgress = 1 * 1024 * 1024
20+
const (
21+
// bodyReaderMinimumProgress is the minimum progress we consider a good reason to retry
22+
bodyReaderMinimumProgress = 1 * 1024 * 1024
23+
// bodyReaderMSSinceLastRetry is the minimum time since a last retry we consider a good reason to retry
24+
bodyReaderMSSinceLastRetry = 60 * 1_000
25+
)
2226

2327
// bodyReader is an io.ReadCloser returned by dockerImageSource.GetBlob,
2428
// which can transparently resume some (very limited) kinds of aborted connections.
@@ -221,13 +225,21 @@ func (br *bodyReader) errorIfNotReconnecting(originalErr error, redactedURL stri
221225
logrus.Debugf("Reading blob body from %s failed (%#v), decision inputs: total %d @%.3f ms, last retry %d @%.3f ms, last progress @%.3f ms",
222226
redactedURL, originalErr, br.offset, msSinceFirstConnection, br.lastRetryOffset, msSinceLastRetry, msSinceLastSuccess)
223227
progress := br.offset - br.lastRetryOffset
224-
if progress < bodyReaderMinimumProgress {
225-
logrus.Debugf("Not reconnecting to %s because only %d bytes progress made", redactedURL, progress)
226-
return fmt.Errorf("(heuristic tuning data: total %d @%.3f ms, last retry %d @%.3f ms, last progress @ %.3f ms): %w",
227-
br.offset, msSinceFirstConnection, br.lastRetryOffset, msSinceLastRetry, msSinceLastSuccess, originalErr)
228+
if progress >= bodyReaderMinimumProgress {
229+
logrus.Infof("Reading blob body from %s failed (%v), reconnecting after %d bytes…", redactedURL, originalErr, progress)
230+
return nil
231+
}
232+
if br.lastRetryTime == (time.Time{}) || msSinceLastRetry >= bodyReaderMSSinceLastRetry {
233+
if br.lastRetryTime == (time.Time{}) {
234+
logrus.Infof("Reading blob body from %s failed (%v), reconnecting (first reconnection)…", redactedURL, originalErr)
235+
} else {
236+
logrus.Infof("Reading blob body from %s failed (%v), reconnecting after %.3f ms…", redactedURL, originalErr, msSinceLastRetry)
237+
}
238+
return nil
228239
}
229-
logrus.Infof("Reading blob body from %s failed (%v), reconnecting…", redactedURL, originalErr)
230-
return nil
240+
logrus.Debugf("Not reconnecting to %s: insufficient progress %d / time since last retry %.3f ms", redactedURL, progress, msSinceLastRetry)
241+
return fmt.Errorf("(heuristic tuning data: total %d @%.3f ms, last retry %d @%.3f ms, last progress @ %.3f ms): %w",
242+
br.offset, msSinceFirstConnection, br.lastRetryOffset, msSinceLastRetry, msSinceLastSuccess, originalErr)
231243
}
232244

233245
// Close implements io.ReadCloser

0 commit comments

Comments
 (0)