-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add hard-coded deadline for reflection stream. #150
Changes from 5 commits
42436ae
b9d3df1
0e77e01
08fd444
6929a23
117c215
958a2e2
6d49288
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -65,8 +65,7 @@ namespace cli | |||||
return m_connections[f_serverAddress].descPool; | ||||||
} | ||||||
|
||||||
grpc::Status ConnectionManager::closeDescDbWithDeadline(std::string f_serverAddress, | ||||||
std::optional<std::chrono::time_point<std::chrono::system_clock>> 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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
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(); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,21 +372,29 @@ void DescDbProxy::getDescriptors(const std::string &f_hostAddress) | |
} | ||
} | ||
|
||
grpc::Status DescDbProxy::closeDescDbStream(std::optional<std::chrono::time_point<std::chrono::system_clock>> deadline) | ||
grpc::Status DescDbProxy::closeDescDbStream() | ||
{ | ||
grpc::Status status; | ||
if ( m_reflectionDescDb == nullptr ) | ||
{ | ||
return grpc::Status::OK; | ||
return status; | ||
} | ||
return m_reflectionDescDb->closeStreamWithDeadline(deadline); | ||
status = m_reflectionDescDb->closeDescDbStream(); | ||
if(not status.ok()) | ||
{ | ||
//failure to close stream leads to invalid cache, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good thought :) |
||
//removing it here so it will be written again next time. | ||
std::string cacheFilePath = prepareCacheFile(); | ||
std::filesystem::remove(cacheFilePath); | ||
} | ||
return status; | ||
} | ||
|
||
DescDbProxy::DescDbProxy(bool disableCache, const std::string &hostAddress, std::shared_ptr<grpc::Channel> channel, | ||
ArgParse::ParsedElement &parseTree) | ||
{ | ||
m_channel = channel; | ||
m_parseTree = parseTree; | ||
m_disableCache = disableCache; | ||
if(disableCache) | ||
{ | ||
// Get Desc directly via reflection and without touching localDB | ||
|
@@ -410,4 +418,8 @@ DescDbProxy::DescDbProxy(bool disableCache, const std::string &hostAddress, std: | |
} | ||
} | ||
|
||
DescDbProxy::~DescDbProxy(){} | ||
DescDbProxy::~DescDbProxy() | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, isn't destructor called each time gwhisper terminates? If so, we would invalidate the cache each time. This would make the cache use-less :P It's only purpose is to transport descriptr info from one invocation the the next. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes the proxy dtor is called evrytime. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, understand. Maybe add a comment in the destructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
closeDescDbStream(); //close it here to ensure invalid cache file is removed if an error occurs. | ||
//enforcing descDb repopulation next time. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ using grpc::reflection::v1alpha::ServerReflection; | |
using grpc::reflection::v1alpha::ServerReflectionRequest; | ||
using grpc::reflection::v1alpha::ServerReflectionResponse; | ||
|
||
const uint8_t g_timeoutGrpcMainStreamSeconds = 20; //using default gwhisper timeout of 20 seconds. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. increased since we already have default rpc timeout of 30secs anyway, is that too big? we saw that 10secs easily times out on slower systems. |
||
namespace grpc { | ||
|
||
ProtoReflectionDescriptorDatabase::ProtoReflectionDescriptorDatabase( | ||
|
@@ -300,6 +301,9 @@ void ProtoReflectionDescriptorDatabase::AddFileFromResponse( | |
const std::shared_ptr<ProtoReflectionDescriptorDatabase::ClientStream> | ||
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<std::chrono::time_point<std::chrono::system_clock>> 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, " | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done