Skip to content

[EXPORTER] Avoid std::terminate when the OTLP HTTP response body cannot be processed - #4587

Open
YuEfSaEDU wants to merge 1 commit into
open-telemetry:mainfrom
YuEfSaEDU:fix/onresponse-noexcept-terminate-4534
Open

YuEfSaEDU wants to merge 1 commit into
open-telemetry:mainfrom
YuEfSaEDU:fix/onresponse-noexcept-terminate-4534

Conversation

@YuEfSaEDU

Copy link
Copy Markdown

ResponseHandler::OnResponse is declared noexcept, but copying the response body and parsing it with JsonStringToMessage or ParseFromString can throw; any exception escaping a noexcept function calls std::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 as ExportResult::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_test cover the JSON and protobuf parse-failure paths against the nosend stub client, asserting a single failure report and that ForceFlush returns without waiting out the deadline.

Fixes #4534

…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
@YuEfSaEDU
YuEfSaEDU requested a review from a team as a code owner September 17, 2026 02:44
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 17, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: YuEfSaEDU / name: Yusuf Efe Saglam (33d59b7)

@mateenali66 mateenali66 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.83333% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.48%. Comparing base (e62f627) to head (33d59b7).

Files with missing lines Patch % Lines
exporters/otlp/src/otlp_http_client.cc 70.84% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
exporters/otlp/src/otlp_http_client.cc 72.73% <70.84%> (-0.75%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OnResponse() can call std::terminate() when the response body fails to parse as JSON/protobuf

2 participants