Skip to content

Commit

Permalink
Fix shutdown timeout
Browse files Browse the repository at this point in the history
Signed-off-by: owentou <[email protected]>
  • Loading branch information
owent committed Feb 14, 2022
1 parent 1e8e9dd commit a273ac3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions exporters/ostream/src/log_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ sdk::common::ExportResult OStreamLogExporter::Export(
<< " severity_num : " << static_cast<int>(log_record->GetSeverity()) << "\n"
<< " severity_text : ";

int severity_index = static_cast<int>(log_record->GetSeverity());
std::size_t severity_index = static_cast<std::size_t>(log_record->GetSeverity());
if (severity_index < 0 ||
severity_index >= std::extent<decltype(opentelemetry::logs::SeverityNumToText)>::value)
{
Expand Down Expand Up @@ -181,7 +181,7 @@ sdk::common::ExportResult OStreamLogExporter::Export(
return sdk::common::ExportResult::kSuccess;
}

bool OStreamLogExporter::Shutdown(std::chrono::microseconds timeout) noexcept
bool OStreamLogExporter::Shutdown(std::chrono::microseconds) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
Expand Down
21 changes: 15 additions & 6 deletions exporters/otlp/src/otlp_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ OtlpHttpClient::~OtlpHttpClient()
{
if (!isShutdown())
{
Shutdown(std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::time_point::max() - std::chrono::steady_clock::now()));
Shutdown();
}

// Wait for all the sessions to finish
Expand Down Expand Up @@ -756,10 +755,20 @@ bool OtlpHttpClient::Shutdown(std::chrono::microseconds timeout) noexcept

// Wait for all the sessions to finish
std::unique_lock<std::mutex> lock(session_waker_lock_);
session_waker_.wait_for(lock, timeout, [this] {
std::lock_guard<std::recursive_mutex> guard{session_manager_lock_};
return running_sessions_.empty();
});
if (timeout == std::chrono::microseconds::zero())
{
session_waker_.wait(lock, [this] {
std::lock_guard<std::recursive_mutex> guard{session_manager_lock_};
return running_sessions_.empty();
});
}
else
{
session_waker_.wait_for(lock, timeout, [this] {
std::lock_guard<std::recursive_mutex> guard{session_manager_lock_};
return running_sessions_.empty();
});
}

while (cleanupGCSessions())
;
Expand Down

0 comments on commit a273ac3

Please sign in to comment.