@@ -198,19 +198,20 @@ func (br *bodyReader) Read(p []byte) (int, error) {
198
198
}
199
199
}
200
200
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
+ }
203
207
return float64 (time .Since (tm ).Nanoseconds ()) / 1_000_000.0
204
208
}
205
209
206
210
// errorIfNotReconnecting makes a heuristic decision whether we should reconnect after err at redactedURL; if so, it returns nil,
207
211
// otherwise it returns an appropriate error to return to the caller (possibly augmented with data about the heuristic)
208
212
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 )
214
215
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" ,
215
216
redactedURL , originalErr , br .lastRetryOffset , br .offset , totalTime , failureTime )
216
217
progress := br .offset - br .lastRetryOffset
0 commit comments