From a7a1dd63a4885b7fecf8ccad45a8afb68ac224ab Mon Sep 17 00:00:00 2001 From: varshneydevansh Date: Wed, 23 Aug 2023 18:45:40 +0530 Subject: [PATCH 1/2] feat: timeout argument for client.sample --- reverb/cc/sampler.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/reverb/cc/sampler.cc b/reverb/cc/sampler.cc index 238764a..2b9bfba 100644 --- a/reverb/cc/sampler.cc +++ b/reverb/cc/sampler.cc @@ -208,6 +208,13 @@ class GrpcSamplerWorker : public SamplerWorker { } context_ = std::make_unique(); context_->set_wait_for_ready(false); + + // Buffer time to account for connection overhead + constexpr auto CONNECTION_BUFFER_TIME = std::chrono::milliseconds(200); + + // Setting the deadline for the gRPC context + context_->set_deadline(absl::ToChronoTime(absl::Now() + rate_limiter_timeout + CONNECTION_BUFFER_TIME)); + stream = stub_->SampleStream(context_.get()); } From a138193a7cfa2c9ab146ff23a94cd40bace1a735 Mon Sep 17 00:00:00 2001 From: varshneydevansh Date: Wed, 23 Aug 2023 19:58:54 +0530 Subject: [PATCH 2/2] corrected with the if-clause --- reverb/cc/sampler.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/reverb/cc/sampler.cc b/reverb/cc/sampler.cc index 2b9bfba..f8ab10b 100644 --- a/reverb/cc/sampler.cc +++ b/reverb/cc/sampler.cc @@ -209,11 +209,12 @@ class GrpcSamplerWorker : public SamplerWorker { context_ = std::make_unique(); context_->set_wait_for_ready(false); - // Buffer time to account for connection overhead - constexpr auto CONNECTION_BUFFER_TIME = std::chrono::milliseconds(200); - - // Setting the deadline for the gRPC context - context_->set_deadline(absl::ToChronoTime(absl::Now() + rate_limiter_timeout + CONNECTION_BUFFER_TIME)); + if (rate_limiter_timeout != absl::InfiniteDuration()) { + // Buffer time to account for connection overhead + constexpr auto CONNECTION_BUFFER_TIME = std::chrono::milliseconds(200); + // Setting the deadline for the gRPC context + context_->set_deadline(absl::ToChronoTime(absl::Now() + rate_limiter_timeout + CONNECTION_BUFFER_TIME)); + } stream = stub_->SampleStream(context_.get()); }