Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.2.0] Don't fetch empty digest on failure status in FetchBlobResponse #25277

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ java_library(
"//third_party:jsr305",
"//third_party/grpc-java:grpc-jar",
"@com_google_protobuf//:protobuf_java_util",
"@googleapis//google/rpc:rpc_java_proto",
"@remoteapis//:build_bazel_remote_asset_v1_remote_asset_java_grpc",
"@remoteapis//:build_bazel_remote_asset_v1_remote_asset_java_proto",
"@remoteapis//:build_bazel_remote_execution_v2_remote_execution_java_proto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
import com.google.devtools.build.lib.remote.util.Utils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.protobuf.util.Timestamps;
import com.google.rpc.Code;
import io.grpc.CallCredentials;
import io.grpc.Channel;
import io.grpc.StatusRuntimeException;
import io.grpc.protobuf.StatusProto;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -160,6 +162,9 @@ public void download(
channel ->
fetchBlockingStub(remoteActionExecutionContext, channel)
.fetchBlob(request)));
if (response.getStatus().getCode() != Code.OK_VALUE) {
throw StatusProto.toStatusRuntimeException(response.getStatus());
}
final Digest blobDigest = response.getBlobDigest();

retrier.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ java_library(
"//third_party/grpc-java:grpc-jar",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@googleapis//google/rpc:rpc_java_proto",
"@remoteapis//:build_bazel_remote_asset_v1_remote_asset_java_grpc",
"@remoteapis//:build_bazel_remote_asset_v1_remote_asset_java_proto",
"@remoteapis//:build_bazel_remote_execution_v2_remote_execution_java_proto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import com.google.devtools.common.options.Options;
import com.google.protobuf.ByteString;
import com.google.protobuf.util.Timestamps;
import com.google.rpc.Code;
import com.google.rpc.Status;
import io.grpc.CallCredentials;
import io.grpc.ManagedChannel;
import io.grpc.Server;
Expand Down Expand Up @@ -277,6 +279,50 @@ public void fetchBlob(
assertThat(downloaded).isEqualTo(content);
}

@Test
public void testStatusHandling() throws Exception {
final byte[] content = "example content".getBytes(UTF_8);
serviceRegistry.addService(
new FetchImplBase() {
@Override
public void fetchBlob(
FetchBlobRequest request, StreamObserver<FetchBlobResponse> responseObserver) {
assertThat(request)
.isEqualTo(
FetchBlobRequest.newBuilder()
.setDigestFunction(DIGEST_UTIL.getDigestFunction())
.setOldestContentAccepted(
Timestamps.fromMillis(clock.advance(Duration.ofHours(1))))
.addUris("http://example.com/content.txt")
.build());
responseObserver.onNext(
FetchBlobResponse.newBuilder()
.setStatus(
Status.newBuilder()
.setCode(Code.PERMISSION_DENIED_VALUE)
.setMessage("permission denied")
.build())
.setUri("http://example.com/content.txt")
.build());
responseObserver.onCompleted();
}
});
final RemoteCacheClient cacheClient = new InMemoryCacheClient();
final GrpcRemoteDownloader downloader =
newDownloader(cacheClient, /* fallbackDownloader= */ null);
// Add a cache entry for the empty Digest to verify that the implementation checks the status
// before fetching the digest.
getFromFuture(cacheClient.uploadBlob(context, Digest.getDefaultInstance(), ByteString.EMPTY));

var exception =
assertThrows(
IOException.class,
() ->
downloadBlob(
downloader, new URL("http://example.com/content.txt"), Optional.empty()));
assertThat(exception).hasMessageThat().contains("permission denied");
}

@Test
public void testPropagateChecksum() throws Exception {
final byte[] content = "example content".getBytes(UTF_8);
Expand Down
Loading