Skip to content

Commit 0581201

Browse files
committed
Turn millisecondsSince into millisecondsSinceOptional
... because we will have more cases of the NaN case, so share that code path. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent 7addf09 commit 0581201

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

docker/body_reader.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,20 @@ func (br *bodyReader) Read(p []byte) (int, error) {
198198
}
199199
}
200200

201-
// millisecondsSince is like time.Since(tm).Milliseconds, but it returns a floating-point value
202-
func millisecondsSince(tm time.Time) float64 {
201+
// millisecondsSinceOptional is like time.Since(tm).Milliseconds, but it returns a floating-point value.
202+
// If the input time is time.Time{}, it returns math.NaN()
203+
func millisecondsSinceOptional(tm time.Time) float64 {
204+
if tm == (time.Time{}) {
205+
return math.NaN()
206+
}
203207
return float64(time.Since(tm).Nanoseconds()) / 1_000_000.0
204208
}
205209

206210
// errorIfNotReconnecting makes a heuristic decision whether we should reconnect after err at redactedURL; if so, it returns nil,
207211
// otherwise it returns an appropriate error to return to the caller (possibly augmented with data about the heuristic)
208212
func (br *bodyReader) errorIfNotReconnecting(originalErr error, redactedURL string) error {
209-
totalTime := millisecondsSince(br.firstConnectionTime)
210-
failureTime := math.NaN()
211-
if (br.lastSuccessTime != time.Time{}) {
212-
failureTime = millisecondsSince(br.lastSuccessTime)
213-
}
213+
totalTime := millisecondsSinceOptional(br.firstConnectionTime)
214+
failureTime := millisecondsSinceOptional(br.lastSuccessTime)
214215
logrus.Debugf("Reading blob body from %s failed (%#v), decision inputs: lastRetryOffset %d, offset %d, %.3f ms since first connection, %.3f ms since last progress",
215216
redactedURL, originalErr, br.lastRetryOffset, br.offset, totalTime, failureTime)
216217
progress := br.offset - br.lastRetryOffset

0 commit comments

Comments
 (0)