Skip to content

Commit

Permalink
add dealine to close main server info fetch stream for unary rpcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahman Abber Tahir committed Nov 14, 2023
1 parent 92ff8b8 commit 31f87fd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion third_party/gRPC_utils/proto_reflection_descriptor_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using grpc::reflection::v1alpha::ServerReflection;
using grpc::reflection::v1alpha::ServerReflectionRequest;
using grpc::reflection::v1alpha::ServerReflectionResponse;

const uint8_t g_timeoutGrpcMainStreamSeconds = 10; //using default gwhisper timeout of 10 seconds.
namespace grpc {

ProtoReflectionDescriptorDatabase::ProtoReflectionDescriptorDatabase(
Expand All @@ -50,6 +51,16 @@ ProtoReflectionDescriptorDatabase::~ProtoReflectionDescriptorDatabase() {
fprintf(stderr,
"Reflection request not implemented; "
"is the ServerReflection service enabled?\n");
}
else if (status.error_code() == StatusCode::DEADLINE_EXCEEDED) {
fprintf(stderr,
"ServerReflectionInfo rpc failed. Grpc Server failed to close the stream within %d seconds.\n"
"Error code: %d, message: %s, "
"debug info: %s\n",
g_timeoutGrpcMainStreamSeconds,
static_cast<int>(status.error_code()),
status.error_message().c_str(),
ctx_.debug_error_string().c_str());
} else {
fprintf(stderr,
"ServerReflectionInfo rpc failed. Error code: %d, message: %s, "
Expand Down Expand Up @@ -315,7 +326,11 @@ void ProtoReflectionDescriptorDatabase::AddFileFromResponse(

const std::shared_ptr<ProtoReflectionDescriptorDatabase::ClientStream>
ProtoReflectionDescriptorDatabase::GetStream() {
if (!stream_) {
if (!stream_) //only assign deadline to a unary rpc.
{
std::chrono::system_clock::time_point deadline =
std::chrono::system_clock::now() + std::chrono::seconds(g_timeoutGrpcMainStreamSeconds);
ctx_.set_deadline(deadline);
stream_ = stub_->ServerReflectionInfo(&ctx_);
}
return stream_;
Expand Down

0 comments on commit 31f87fd

Please sign in to comment.