Skip to content

Commit 4de2f81

Browse files
committed
Cleanup
1 parent 6de20c1 commit 4de2f81

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
361361
std::unordered_map<uint64_t, std::shared_ptr<Session>> pending_to_abort_sessions_;
362362
std::unordered_map<uint64_t, HttpCurlEasyResource> pending_to_remove_session_handles_;
363363
std::list<std::shared_ptr<Session>> pending_to_remove_sessions_;
364-
std::deque<Session *> pending_to_retry_sessions_;
364+
std::deque<std::shared_ptr<Session>> pending_to_retry_sessions_;
365365

366366
std::mutex background_thread_m_;
367367
std::unique_ptr<std::thread> background_thread_;

ext/src/http/client/curl/http_client_curl.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ bool HttpClient::MaybeSpawnBackgroundThread()
486486

487487
if (operation->IsRetryable())
488488
{
489-
self->pending_to_retry_sessions_.push_front(session);
489+
self->pending_to_retry_sessions_.push_front(hold_session);
490490
}
491491
}
492492
}
@@ -790,7 +790,8 @@ bool HttpClient::doRemoveSessions()
790790

791791
bool HttpClient::doRetrySessions()
792792
{
793-
auto has_data = false;
793+
const auto now = std::chrono::system_clock::now();
794+
auto has_data = false;
794795

795796
// Assumptions:
796797
// - This is a FIFO list so older sessions, pushed at the front, always end up at the tail
@@ -807,7 +808,7 @@ bool HttpClient::doRetrySessions()
807808
{
808809
retry_it = decltype(retry_it){pending_to_retry_sessions_.erase(std::next(retry_it).base())};
809810
}
810-
else if (operation->NextRetryTime() < std::chrono::system_clock::now())
811+
else if (operation->NextRetryTime() < now)
811812
{
812813
auto easy_handle = operation->GetCurlEasyHandle();
813814
curl_multi_remove_handle(multi_handle_, easy_handle);

ext/src/http/client/curl/http_operation_curl.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,12 @@ HttpOperation::HttpOperation(opentelemetry::ext::http::client::Method method,
289289
compression_(compression),
290290
is_log_enabled_(is_log_enabled),
291291
retry_policy_(retry_policy),
292-
retry_attempts_(0),
292+
retry_attempts_((retry_policy.max_attempts > 0U &&
293+
retry_policy.initial_backoff > SecondsDecimal::zero() &&
294+
retry_policy.max_backoff > SecondsDecimal::zero() &&
295+
retry_policy.backoff_multiplier > 0.0f)
296+
? 0
297+
: retry_policy.max_attempts),
293298
response_code_(0)
294299
{
295300
/* get a curl handle */

ext/test/http/curl_http_test.cc

+34
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,40 @@ TEST_F(BasicCurlHttpTests, CurlHttpOperations)
350350
delete handler;
351351
}
352352

353+
TEST_F(BasicCurlHttpTests, RetryPolicyEnabled)
354+
{
355+
RetryEventHandler handler;
356+
http_client::HttpSslOptions no_ssl;
357+
http_client::Body body;
358+
http_client::Headers headers;
359+
http_client::Compression compression = http_client::Compression::kNone;
360+
http_client::RetryPolicy retry_policy = {5, 1.0f, 5.0f, 1.5f};
361+
362+
curl::HttpOperation operation(http_client::Method::Post, "http://127.0.0.1:19000/retry/", no_ssl,
363+
&handler, headers, body, compression, false,
364+
curl::kDefaultHttpConnTimeout, false, false, retry_policy);
365+
366+
ASSERT_EQ(CURLE_OK, operation.Send());
367+
ASSERT_TRUE(operation.IsRetryable());
368+
}
369+
370+
TEST_F(BasicCurlHttpTests, RetryPolicyDisabled)
371+
{
372+
RetryEventHandler handler;
373+
http_client::HttpSslOptions no_ssl;
374+
http_client::Body body;
375+
http_client::Headers headers;
376+
http_client::Compression compression = http_client::Compression::kNone;
377+
http_client::RetryPolicy no_retry_policy = {0, 0.0f, 0.0f, 0.0f};
378+
379+
curl::HttpOperation operation(http_client::Method::Post, "http://127.0.0.1:19000/retry/", no_ssl,
380+
&handler, headers, body, compression, false,
381+
curl::kDefaultHttpConnTimeout, false, false, no_retry_policy);
382+
383+
ASSERT_EQ(CURLE_OK, operation.Send());
384+
ASSERT_FALSE(operation.IsRetryable());
385+
}
386+
353387
TEST_F(BasicCurlHttpTests, ExponentialBackoffRetry)
354388
{
355389
using ::testing::AllOf;

0 commit comments

Comments
 (0)