fix(3p/nix): Don't reuse ClientContext

It turns out these aren't supposed to be reused after the first request
- reusing it was causing things to blow up.

Change-Id: I935f1ee82ed4e7f26528ae105c8fa2501fa81b97
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1559
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2020-08-01 20:22:33 -04:00 committed by glittershark
parent b6bab664db
commit e0d25449e3

View file

@ -30,7 +30,6 @@ using grpc::ClientContext;
using nix::proto::WorkerService; using nix::proto::WorkerService;
static google::protobuf::Empty kEmpty; static google::protobuf::Empty kEmpty;
static ClientContext ctx;
proto::StorePath StorePath(const Path& path) { proto::StorePath StorePath(const Path& path) {
proto::StorePath store_path; proto::StorePath store_path;
@ -65,12 +64,14 @@ void const RpcStore::SuccessOrThrow(const grpc::Status& status) const {
} }
bool RpcStore::isValidPathUncached(const Path& path) { bool RpcStore::isValidPathUncached(const Path& path) {
ClientContext ctx;
proto::IsValidPathResponse resp; proto::IsValidPathResponse resp;
SuccessOrThrow(stub_->IsValidPath(&ctx, StorePath(path), &resp)); SuccessOrThrow(stub_->IsValidPath(&ctx, StorePath(path), &resp));
return resp.is_valid(); return resp.is_valid();
} }
PathSet RpcStore::queryAllValidPaths() { PathSet RpcStore::queryAllValidPaths() {
ClientContext ctx;
proto::StorePaths paths; proto::StorePaths paths;
SuccessOrThrow(stub_->QueryAllValidPaths(&ctx, kEmpty, &paths)); SuccessOrThrow(stub_->QueryAllValidPaths(&ctx, kEmpty, &paths));
return FillFrom<PathSet>(paths.paths()); return FillFrom<PathSet>(paths.paths());
@ -78,6 +79,7 @@ PathSet RpcStore::queryAllValidPaths() {
PathSet RpcStore::queryValidPaths(const PathSet& paths, PathSet RpcStore::queryValidPaths(const PathSet& paths,
SubstituteFlag maybeSubstitute) { SubstituteFlag maybeSubstitute) {
ClientContext ctx;
proto::StorePaths store_paths; proto::StorePaths store_paths;
for (const auto& path : paths) { for (const auto& path : paths) {
store_paths.add_paths(path); store_paths.add_paths(path);
@ -90,6 +92,7 @@ PathSet RpcStore::queryValidPaths(const PathSet& paths,
void RpcStore::queryPathInfoUncached( void RpcStore::queryPathInfoUncached(
const Path& path, const Path& path,
Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept { Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept {
ClientContext ctx;
proto::StorePath store_path; proto::StorePath store_path;
store_path.set_path(path); store_path.set_path(path);
@ -127,24 +130,28 @@ void RpcStore::queryPathInfoUncached(
} }
void RpcStore::queryReferrers(const Path& path, PathSet& referrers) { void RpcStore::queryReferrers(const Path& path, PathSet& referrers) {
ClientContext ctx;
proto::StorePaths paths; proto::StorePaths paths;
SuccessOrThrow(stub_->QueryReferrers(&ctx, StorePath(path), &paths)); SuccessOrThrow(stub_->QueryReferrers(&ctx, StorePath(path), &paths));
referrers.insert(paths.paths().begin(), paths.paths().end()); referrers.insert(paths.paths().begin(), paths.paths().end());
} }
PathSet RpcStore::queryValidDerivers(const Path& path) { PathSet RpcStore::queryValidDerivers(const Path& path) {
ClientContext ctx;
proto::StorePaths paths; proto::StorePaths paths;
SuccessOrThrow(stub_->QueryValidDerivers(&ctx, StorePath(path), &paths)); SuccessOrThrow(stub_->QueryValidDerivers(&ctx, StorePath(path), &paths));
return FillFrom<PathSet>(paths.paths()); return FillFrom<PathSet>(paths.paths());
} }
PathSet RpcStore::queryDerivationOutputs(const Path& path) { PathSet RpcStore::queryDerivationOutputs(const Path& path) {
ClientContext ctx;
proto::StorePaths paths; proto::StorePaths paths;
SuccessOrThrow(stub_->QueryDerivationOutputs(&ctx, StorePath(path), &paths)); SuccessOrThrow(stub_->QueryDerivationOutputs(&ctx, StorePath(path), &paths));
return FillFrom<PathSet>(paths.paths()); return FillFrom<PathSet>(paths.paths());
} }
StringSet RpcStore::queryDerivationOutputNames(const Path& path) { StringSet RpcStore::queryDerivationOutputNames(const Path& path) {
ClientContext ctx;
proto::DerivationOutputNames output_names; proto::DerivationOutputNames output_names;
SuccessOrThrow( SuccessOrThrow(
stub_->QueryDerivationOutputNames(&ctx, StorePath(path), &output_names)); stub_->QueryDerivationOutputNames(&ctx, StorePath(path), &output_names));
@ -152,6 +159,7 @@ StringSet RpcStore::queryDerivationOutputNames(const Path& path) {
} }
Path RpcStore::queryPathFromHashPart(const std::string& hashPart) { Path RpcStore::queryPathFromHashPart(const std::string& hashPart) {
ClientContext ctx;
proto::StorePath path; proto::StorePath path;
proto::HashPart proto_hash_part; proto::HashPart proto_hash_part;
proto_hash_part.set_hash_part(hashPart); proto_hash_part.set_hash_part(hashPart);
@ -160,6 +168,7 @@ Path RpcStore::queryPathFromHashPart(const std::string& hashPart) {
} }
PathSet RpcStore::querySubstitutablePaths(const PathSet& paths) { PathSet RpcStore::querySubstitutablePaths(const PathSet& paths) {
ClientContext ctx;
proto::StorePaths result; proto::StorePaths result;
SuccessOrThrow( SuccessOrThrow(
stub_->QuerySubstitutablePaths(&ctx, StorePaths(paths), &result)); stub_->QuerySubstitutablePaths(&ctx, StorePaths(paths), &result));
@ -168,6 +177,7 @@ PathSet RpcStore::querySubstitutablePaths(const PathSet& paths) {
void RpcStore::querySubstitutablePathInfos(const PathSet& paths, void RpcStore::querySubstitutablePathInfos(const PathSet& paths,
SubstitutablePathInfos& infos) { SubstitutablePathInfos& infos) {
ClientContext ctx;
proto::SubstitutablePathInfos result; proto::SubstitutablePathInfos result;
SuccessOrThrow( SuccessOrThrow(
stub_->QuerySubstitutablePathInfos(&ctx, StorePaths(paths), &result)); stub_->QuerySubstitutablePathInfos(&ctx, StorePaths(paths), &result));