fix(images): prevent divide by zero in LoggedPullImageResultCallback (#11416) - #11953
fix(images): prevent divide by zero in LoggedPullImageResultCallback (#11416)#11953arimu1 wants to merge 1 commit into
Conversation
|
I ran into the same The fix and the test hold up. With only the new With the full PR, it passes. So the test pins the change rather than passing either way. Worth noting the reproduction is Spotless will fail CI. PullResponseItem item = mapper.readValue(
"{\"status\":\"Download complete\",\"id\":\"layer1\"}",
PullResponseItem.class
);The One thing worth flagging before this gets a decision. #11417 fixes the same issue and is approved, but it does not work. It computes I applied #11417 onto Optional. If the intent behind #11417 (a real rate for sub-second pulls) is wanted, final long millis = start != null ? Duration.between(start, Instant.now()).toMillis() : 0;
...
FileUtils.byteCountToDisplaySize(downloadedLayerSize * 1000 / Math.max(1, millis))That also removes the small inconsistency this PR leaves behind, where a sub-second pull logs |
59d6fe4 to
67f0d95
Compare
Fixes #11416
Description
When pulling an image completes in less than 1 second (sub-second duration),
Duration.between(start, Instant.now()).getSeconds()returns0.Calculating transfer speed as
downloadedLayerSize / durationthrowsjava.lang.ArithmeticException: / by zero.This PR uses
Math.max(1, duration)when calculating transfer speed inLoggedPullImageResultCallback#onComplete(), preventingArithmeticException.Changes
LoggedPullImageResultCallback.javato useMath.max(1, duration)when calculating transfer rate.LoggedPullImageResultCallbackTest.javacovering zero-duration pull completion.