Increase gRPC timeout for AddTrajectory (#1426)

A common use case is that a gRPC server and a gRPC--ROS bridge node
are started at the same time.
Setting the timeout of the stub higher ensures that these can connect
even when the gRPC server starts up slowly.
master
gaschler 2018-09-14 10:32:47 +02:00 committed by Wally B. Feed
parent 601fc3c7d0
commit 2e8df42f88
1 changed files with 9 additions and 5 deletions

View File

@ -36,7 +36,10 @@ namespace cloud {
namespace { namespace {
using absl::make_unique; using absl::make_unique;
constexpr int kConnectionTimeoutInSeconds = 10; constexpr int kChannelTimeoutSeconds = 10;
constexpr int kRetryBaseDelayMilliseconds = 500;
constexpr float kRetryDelayFactor = 2.0;
constexpr int kMaxRetries = 5;
} // namespace } // namespace
@ -50,7 +53,7 @@ MapBuilderStub::MapBuilderStub(const std::string& server_address,
<< " with client_id " << client_id; << " with client_id " << client_id;
std::chrono::system_clock::time_point deadline( std::chrono::system_clock::time_point deadline(
std::chrono::system_clock::now() + std::chrono::system_clock::now() +
std::chrono::seconds(kConnectionTimeoutInSeconds)); std::chrono::seconds(kChannelTimeoutSeconds));
if (!client_channel_->WaitForConnected(deadline)) { if (!client_channel_->WaitForConnected(deadline)) {
LOG(FATAL) << "Failed to connect to " << server_address; LOG(FATAL) << "Failed to connect to " << server_address;
} }
@ -67,9 +70,10 @@ int MapBuilderStub::AddTrajectoryBuilder(
*request.add_expected_sensor_ids() = cloud::ToProto(sensor_id); *request.add_expected_sensor_ids() = cloud::ToProto(sensor_id);
} }
async_grpc::Client<handlers::AddTrajectorySignature> client( async_grpc::Client<handlers::AddTrajectorySignature> client(
client_channel_, common::FromSeconds(10), client_channel_, common::FromSeconds(kChannelTimeoutSeconds),
async_grpc::CreateLimitedBackoffStrategy(common::FromMilliseconds(100), async_grpc::CreateLimitedBackoffStrategy(
2.f, 5)); common::FromMilliseconds(kRetryBaseDelayMilliseconds),
kRetryDelayFactor, kMaxRetries));
CHECK(client.Write(request)); CHECK(client.Write(request));
// Construct trajectory builder stub. // Construct trajectory builder stub.