Skip to content

Instantly share code, notes, and snippets.

@coryan
Last active May 14, 2022 17:04
Show Gist options
  • Save coryan/17deb8fa31bdae76d177057cb1278757 to your computer and use it in GitHub Desktop.
Save coryan/17deb8fa31bdae76d177057cb1278757 to your computer and use it in GitHub Desktop.
Reproduce gRPC + google-cloud-cpp storage crash
# syntax=docker/dockerfile:1.3-labs
# test using
# docker buildx build --progress plain -t test - <Dockerfile
FROM rockylinux:8
RUN dnf -y update
RUN dnf -y groupinstall "Development Tools"
RUN dnf -y install gcc-toolset-10-gcc curl
RUN dnf -y install gdb
RUN curl -sSL https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -o /usr/bin/bazel
RUN chmod 755 /usr/bin/bazel
# RUN scl enable gcc-toolset-10 bash
WORKDIR /var/tmp/build/test
RUN cat >WORKSPACE.bazel <<_EOF_
workspace(name = "repro")
# Add the necessary Starlark functions to fetch google-cloud-cpp.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Fetch the Google Cloud C++ libraries.
# NOTE: Update this version and SHA256 as needed.
http_archive(
name = "com_github_googleapis_google_cloud_cpp",
sha256 = "9f9a2f1250efd47a3c8fbe2a3874b3d8aa45ef43c6d54cfcc764ad27bc78d21d",
strip_prefix = "google-cloud-cpp-1.39.1",
url = "https://github.com/googleapis/google-cloud-cpp/archive/v1.39.1.tar.gz",
)
# Load indirect dependencies due to
# https://github.com/bazelbuild/bazel/issues/1943
load("@com_github_googleapis_google_cloud_cpp//bazel:google_cloud_cpp_deps.bzl", "google_cloud_cpp_deps")
google_cloud_cpp_deps()
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
name = "com_google_googleapis_imports",
cc = True,
grpc = True,
)
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()
_EOF_
RUN cat >BUILD.bazel <<_EOF_
package(default_visibility = ["//visibility:private"])
licenses(["notice"]) # Apache 2.0
cc_binary(
name = "repro",
srcs = [
"repro.cc",
],
deps = [
"@com_github_googleapis_google_cloud_cpp//:experimental-storage-grpc",
],
)
_EOF_
# Use an empty file to initialize the Bazel cache, that speeds up iterations
# for me.
RUN echo '' >repro.cc
RUN bazel build -c dbg @com_github_googleapis_google_cloud_cpp//:experimental-storage-grpc
RUN cat >repro.cc <<_EOF_
#include "google/cloud/storage/client.h"
#include "google/cloud/storage/grpc_plugin.h"
#include <iostream>
#include <memory>
namespace gcs = ::google::cloud::storage;
namespace experimental = ::google::cloud::storage_experimental;
namespace g = ::google::cloud;
struct Helper {
Helper() : client(experimental::DefaultGrpcClient(
g::Options{}
.set<experimental::GrpcPluginOption>("media")
.set<google::cloud::EndpointOption>("google-c2p-experimental:///storage.googleapis.com"))) {}
gcs::Client client;
};
static Helper the_helper;
int main(int argc, char* argv[]) {
auto reader = the_helper.client.ReadObject("test-only-invalid", "quickstart-grpc.txt");
if (!reader) {
std::cerr << "Error reading object: " << reader.status() << "\n";
return 1;
}
return 0;
}
_EOF_
ENV GRPC_XDS_EXPERIMENTAL_ENABLE_AGGREGATE_AND_LOGICAL_DNS_CLUSTER=true
RUN ulimit -c unlimited
RUN bazel build -c dbg :repro
RUN bazel-bin/repro || gdb -ex bt bazel-bin/repro core
RUN if [[ -e core ]]; then exit 1; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment