diff --git a/src/libCli/Call.cpp b/src/libCli/Call.cpp index 287b68f..2f898ea 100644 --- a/src/libCli/Call.cpp +++ b/src/libCli/Call.cpp @@ -191,14 +191,11 @@ namespace cli } //before calling the RPC, close the DescDb connection with a timeout. - grpc::Status dbDescStatus = ConnectionManager::getInstance().closeDescDbWithDeadline(serverAddress, deadline); + grpc::Status dbDescStatus = ConnectionManager::getInstance().closeDescDbStream(serverAddress); if (not dbDescStatus.ok()) { - std::cerr << "Failed to close reflection stream ;( Status code: " << std::to_string(dbDescStatus.error_code()) << " " << cli::getGrpcStatusCodeAsString(dbDescStatus.error_code()) << ", error message: " << dbDescStatus.error_message() << std::endl; - if(dbDescStatus.error_code() == grpc::StatusCode::DEADLINE_EXCEEDED) - { - std::cerr << "Note: You can increase the deadline by setting the --rpcTimeoutMilliseconds option to a number or 'None'." << std::endl; - } + std::cerr << "Failed to close reflection stream ;( Pls try again." << std::endl; + std::cerr << "Status code: " << std::to_string(dbDescStatus.error_code()) << " " << cli::getGrpcStatusCodeAsString(dbDescStatus.error_code()) << ", error message: " << dbDescStatus.error_message() << std::endl; return -1; } diff --git a/src/libCli/ConnectionManager.cpp b/src/libCli/ConnectionManager.cpp index 5e1c084..350ef25 100644 --- a/src/libCli/ConnectionManager.cpp +++ b/src/libCli/ConnectionManager.cpp @@ -65,8 +65,7 @@ namespace cli return m_connections[f_serverAddress].descPool; } - grpc::Status ConnectionManager::closeDescDbWithDeadline(std::string f_serverAddress, - std::optional> deadline) + grpc::Status ConnectionManager::closeDescDbStream(std::string f_serverAddress) { if (m_connections[f_serverAddress].descDbProxy == nullptr) { @@ -75,7 +74,7 @@ namespace cli } //if proxy exists close the stream with a deadline. - grpc::Status status = m_connections[f_serverAddress].descDbProxy->closeDescDbStream(deadline); + grpc::Status status = m_connections[f_serverAddress].descDbProxy->closeDescDbStream(); //delete the proxy, findChannelByAddress() protects from accessing uninitialzed DbProxy. m_connections[f_serverAddress].descDbProxy.reset(); diff --git a/src/libCli/libCli/ConnectionManager.hpp b/src/libCli/libCli/ConnectionManager.hpp index 2515af3..19e8539 100644 --- a/src/libCli/libCli/ConnectionManager.hpp +++ b/src/libCli/libCli/ConnectionManager.hpp @@ -52,13 +52,11 @@ namespace cli /// @returns the gRpc DescriptorPool of the corresponding server address. std::shared_ptr getDescPool(std::string f_serverAddress, ArgParse::ParsedElement &f_parseTree); - /// @brief closes the DescDb stream with a given deadline. + /// @brief closes the DescDb stream with a default deadline. /// @param f_serverAddress server addresss to lookup the assigned DescDbProxy. - /// @param deadline optional dealine for closing the stream. /// @return returns grpc::StatusCode::ABORTED status if no DescDb proxy is attached to the server address, /// otherwise grpc status as a result of stream closure. - grpc::Status closeDescDbWithDeadline(std::string f_serverAddress, - std::optional> deadline); + grpc::Status closeDescDbStream(std::string f_serverAddress); private: ConnectionManager() {} diff --git a/src/libLocalDescriptorCache/DescDbProxy.cpp b/src/libLocalDescriptorCache/DescDbProxy.cpp index 4afbfbb..66baed1 100644 --- a/src/libLocalDescriptorCache/DescDbProxy.cpp +++ b/src/libLocalDescriptorCache/DescDbProxy.cpp @@ -372,13 +372,13 @@ void DescDbProxy::getDescriptors(const std::string &f_hostAddress) } } -grpc::Status DescDbProxy::closeDescDbStream(std::optional> deadline) +grpc::Status DescDbProxy::closeDescDbStream() { if ( m_reflectionDescDb == nullptr ) { return grpc::Status::OK; } - return m_reflectionDescDb->closeStreamWithDeadline(deadline); + return m_reflectionDescDb->closeDescDbStream(); } DescDbProxy::DescDbProxy(bool disableCache, const std::string &hostAddress, std::shared_ptr channel, @@ -386,7 +386,6 @@ DescDbProxy::DescDbProxy(bool disableCache, const std::string &hostAddress, std: { m_channel = channel; m_parseTree = parseTree; - m_disableCache = disableCache; if(disableCache) { // Get Desc directly via reflection and without touching localDB diff --git a/src/libLocalDescriptorCache/DescDbProxy.hpp b/src/libLocalDescriptorCache/DescDbProxy.hpp index f8652a9..674bd04 100644 --- a/src/libLocalDescriptorCache/DescDbProxy.hpp +++ b/src/libLocalDescriptorCache/DescDbProxy.hpp @@ -58,10 +58,9 @@ class DescDbProxy : public grpc::protobuf::DescriptorDatabase{ /// @param hostAdress Address to the current host void getDescriptors(const std::string &hostAddress); - /// @brief close the DescDb stream with a given deadline. If the dealine is not set it waits for the stream to close indefinitely. - /// @param deadline optional deadline to close the DescDb stream. + /// @brief close the DescDb stream with a default deadline. /// @return return grpc status as a result of call the finish() on the DescDb stream. - grpc::Status closeDescDbStream(std::optional> deadline); + grpc::Status closeDescDbStream(); DescDbProxy(bool disableCache, const std::string &hostAddress, std::shared_ptr channel, ArgParse::ParsedElement &parseTree); diff --git a/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h b/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h index 41cdf22..1e758cb 100644 --- a/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h +++ b/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h @@ -82,10 +82,9 @@ class ProtoReflectionDescriptorDatabase : public protobuf::DescriptorDatabase { // Provide a list of full names of registered services bool GetServices(std::vector* output); - /// @brief close the reflection stream with a given deadline. If the dealine is not set it waits for the stream to close indefinitely. - /// @param deadline optional deadline to close the reflection stream. + /// @brief close the reflection stream with a default deadline. /// @return return grpc status as a result of call the finish() on the reflection stream. - grpc::Status closeStreamWithDeadline(std::optional> deadline); + grpc::Status closeDescDbStream(); private: typedef ClientReaderWriter< diff --git a/third_party/gRPC_utils/proto_reflection_descriptor_database.cc b/third_party/gRPC_utils/proto_reflection_descriptor_database.cc index ed374c0..83f8943 100644 --- a/third_party/gRPC_utils/proto_reflection_descriptor_database.cc +++ b/third_party/gRPC_utils/proto_reflection_descriptor_database.cc @@ -32,6 +32,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( @@ -300,6 +301,9 @@ void ProtoReflectionDescriptorDatabase::AddFileFromResponse( const std::shared_ptr ProtoReflectionDescriptorDatabase::GetStream() { if (!stream_) { + 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_; @@ -317,16 +321,13 @@ bool ProtoReflectionDescriptorDatabase::DoOneRequest( return success; } -grpc::Status ProtoReflectionDescriptorDatabase::closeStreamWithDeadline(std::optional> deadline) +grpc::Status ProtoReflectionDescriptorDatabase::closeDescDbStream() { stream_mutex_.lock(); - if( deadline != std::nullopt ) - { - ctx_.set_deadline(deadline.value()); - } auto status = closeStream(); stream_.reset(); + stream_mutex_.unlock(); return status; } @@ -342,6 +343,9 @@ grpc::Status ProtoReflectionDescriptorDatabase::closeStream() 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", g_timeoutGrpcMainStreamSeconds); } else { fprintf(stderr, "ServerReflectionInfo rpc failed. Error code: %d, message: %s, "