From a0f45628ac0fad593db81e066a66a79914d6aa4a Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 18 Aug 2022 05:16:45 -0700 Subject: [PATCH] Verify gRPC cache downloads after flushing the output. Make sure any internal buffers (especially compression) are flushed before attempting verify the digest of the downloaded file. Closes #16072. PiperOrigin-RevId: 468432319 Change-Id: I9d991d563c232113fe29921580f4964c603faf58 --- .../devtools/build/lib/remote/GrpcCacheClient.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java index 5899321ddaea46..c605335a8b81d4 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java @@ -418,19 +418,21 @@ public void onError(Throwable t) { @Override public void onCompleted() { try { + try { + out.flush(); + } finally { + releaseOut(); + } if (digestSupplier != null) { Utils.verifyBlobContents(digest, digestSupplier.get()); } - out.flush(); - future.set(rawOut.getCount()); } catch (IOException e) { future.setException(e); } catch (RuntimeException e) { logger.atWarning().withCause(e).log("Unexpected exception"); future.setException(e); - } finally { - releaseOut(); } + future.set(rawOut.getCount()); } private void releaseOut() {