Conversation
…ot be processed ResponseHandler::OnResponse is noexcept, but copying the response body and parsing it with JsonStringToMessage or ParseFromString can throw. An exception escaping a noexcept function calls std::terminate, so a single malformed or oversized response from the collector could take down the host application. Guard the body copy and both parse branches with try/catch, log any exception through the internal logger, and report the export as ExportResult::kFailure. The completion logic stays outside the guarded region, so the result callback still runs exactly once and no caller is left waiting when an exception is caught. Fixes open-telemetry#4534
|
|
mateenali66
left a comment
There was a problem hiding this comment.
the try needs an #if OPENTELEMETRY_HAVE_EXCEPTIONS guard. bazel.noexcept in ci.yml builds //exporters/otlp:otlp_http_client with -fno-exceptions (only the builders are in NOEXCEPT_EXCLUDES). checked with clang++ -fsyntax-only -fno-exceptions on otlp_http_client.cc: main at e62f627 is clean, 33d59b7 fails at :126 with "cannot use 'try' with exceptions disabled". CI has not run here yet because of the CLA, so it will show up then. otlp_file_client.cc:1454 and periodic_exporting_metric_reader.cc:164 already use that pattern.
separately, both new tests send bodies that make the parser return false (\xff... and {some bad JSON). main already turns those into kFailure at :147 and :153, so neither test reaches the catch. would a stub response whose GetBody() throws work, so the test fails on main?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4587 +/- ##
==========================================
- Coverage 86.52% 86.48% -0.03%
==========================================
Files 525 525
Lines 20464 20472 +8
==========================================
Hits 17704 17704
- Misses 2760 2768 +8
🚀 New features to boost your workflow:
|
ResponseHandler::OnResponseis declarednoexcept, but copying the response body and parsing it withJsonStringToMessageorParseFromStringcan throw; any exception escaping anoexceptfunction callsstd::terminate(), so a single malformed or oversized response from a misbehaving collector or intermediary could take down the exporting process.This change guards the body copy and both parse branches with
try/catch, logs any exception through the internal logger, and reports the export asExportResult::kFailure. The session-completion logic remains outside the guarded region so the result callback still runs exactly once and no caller is left waiting when an exception is caught, matching the completion contract established in #4298.Tests added to
otlp_http_exporter_custom_client_testcover the JSON and protobuf parse-failure paths against the nosend stub client, asserting a single failure report and thatForceFlushreturns without waiting out the deadline.Fixes #4534