Skip to content

Commit 242d52a

Browse files
authored
[SDK] PeriodicExportingMetricReader: future is never set, blocks until timeout (#3030)
1 parent b890969 commit 242d52a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

sdk/src/metrics/export/periodic_exporting_metric_reader.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,22 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce()
106106
std::promise<void> sender;
107107
auto receiver = sender.get_future();
108108

109-
task_thread.reset(new std::thread([this, &cancel_export_for_timeout] {
110-
this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) {
111-
if (cancel_export_for_timeout.load(std::memory_order_acquire))
112-
{
113-
OTEL_INTERNAL_LOG_ERROR(
114-
"[Periodic Exporting Metric Reader] Collect took longer configured time: "
115-
<< this->export_timeout_millis_.count() << " ms, and timed out");
116-
return false;
117-
}
118-
this->exporter_->Export(metric_data);
119-
return true;
120-
});
121-
}));
109+
task_thread.reset(
110+
new std::thread([this, &cancel_export_for_timeout, sender = std::move(sender)] {
111+
this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) {
112+
if (cancel_export_for_timeout.load(std::memory_order_acquire))
113+
{
114+
OTEL_INTERNAL_LOG_ERROR(
115+
"[Periodic Exporting Metric Reader] Collect took longer configured time: "
116+
<< this->export_timeout_millis_.count() << " ms, and timed out");
117+
return false;
118+
}
119+
this->exporter_->Export(metric_data);
120+
return true;
121+
});
122+
123+
const_cast<std::promise<void> &>(sender).set_value();
124+
}));
122125

123126
std::future_status status;
124127
do

0 commit comments

Comments
 (0)