Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4703 +/- ##
==========================================
+ Coverage 86.82% 86.83% +0.01%
==========================================
Files 525 525
Lines 20726 20726
==========================================
+ Hits 17993 17995 +2
+ Misses 2733 2731 -2
🚀 New features to boost your workflow:
|
Target the resource schema string when injecting copy failures so constructor propagation tests do not also exercise the separately reproduced variant-copy cleanup crash. The revised tests still abort against the original noexcept SDK. Add direct IWYU dependencies, keep the replacement new/delete out of line for optimized GCC, and preserve their injection hooks under Valgrind with a test-local environment option.
|
|
||
| TEST(ProviderInitialization, TracerContextResourceCopyThrows) | ||
| { | ||
| Resource resource({{"key", true}}, std::string(kResourceValueSize, 'x')); |
There was a problem hiding this comment.
Could you help clarify what caused the crash with the original string-valued attribute? Was it an issue with the test setup or with cleanup after the resource copy failed?
There was a problem hiding this comment.
It was cleanup during exception unwinding of the partially constructed resource copy, not initial fixture setup. The source Resource was fully constructed before FailAllocation was enabled. The injected std::bad_alloc occurred while copying the owned string attribute; GDB showed the crash in std::variant cleanup (_Variant_storage / _M_reset / std::__do_visit).
I also reproduced this independently with a standalone std::variant containing the same alternative types, without the SDK or GoogleTest, using GCC 14, GCC 15, and Clang with libstdc++. The partially copied variant had index 255 (the valueless sentinel), but cleanup still entered the visit dispatch and segfaulted. That narrows it to the variant-copy cleanup path rather than the fixture setup.
In 71fe088 the tests instead fail the Resource schema-string copy, while retaining a nonempty attribute map. This isolates context-constructor exception propagation; it does not fix the separate variant cleanup issue. I rechecked all six revised resource-copy cases against unmodified adebdf0: each still aborted with exit 134, whereas with this PR they catch std::bad_alloc.
There was a problem hiding this comment.
Thanks, that answers my question. Targeting the schema-string copy makes sense, especially since the revised tests still catch the original bug.
Let's track the remaining attribute-copy cleanup failure in a separate issue and link it from the test comment. I'm happy to approve this fix independently.
|
Thanks for the fix. This lets context construction failures reach the caller instead of terminating. I’ve left one question about the changed test before approving. |
| processors shut down their exporters. | ||
| [#4686](https://github.com/open-telemetry/opentelemetry-cpp/pull/4686) | ||
|
|
||
| * [SDK] Allow allocation failures in tracer, logger, and meter context |
There was a problem hiding this comment.
Since these are public constructors, removing noexcept changes their exception contract and can affect code relying on nothrow construction. Should we mark this as a breaking change in the changelog?
marcalff
left a comment
There was a problem hiding this comment.
LGTM, thanks for the fix and tests.
Fixes #4695
Changes
Remove
noexceptfrom the declarations and definitions ofTracerContext,LoggerContext, andMeterContextconstructors. These constructors copy resources and, for trace/log contexts, allocate a multi-processor. Failures can now unwind through the already-throwing provider constructors to the caller.The production diff is only six constructor-signature lines. Runtime
GetTracer,GetLogger, andGetMeterremain noexcept.Add a dedicated allocation-injection executable: runtime tests target resource schema-string copying in all three contexts/providers and internal processor allocation in trace/log contexts. Injection stays out of other tests; CMake excludes the executable for Windows shared-library builds where executable allocation overrides cannot intercept DLL allocations.
Reproduction and verification
On unmodified upstream
adebdf0c, each of the six context/provider resource-copy tests aborted withstd::bad_allocinstead of reaching its caller's catch block.With the fix:
CI follow-up
<cstddef>explicitly forstd::size_t.new/deleteimplementations out of line on GCC, eliminating the reproduced optimized-Werror=mismatched-new-deletefailures without disabling warnings.VALGRIND_OPTSonly for this Bazel test so its allocation-failure hooks remain active while libcmalloc/freeare still checked. No tests are skipped.std::variantcleanup. Target the Resource's schema-string copy instead, preserving nonempty attributes and the same constructor-propagation check without also testing that separate cleanup path.The revised six resource-copy regressions were linked against unmodified
adebdf0c: every one still aborted with exit 134. They pass with this PR, so changing the allocation target does not hide the originalnoexceptbug. This follow-up changes only the test source and its Bazel target; the six-line production constructor fix is unchanged.Follow-up verification:
-O3 -Werror/maintainer-warning compilation passed for both ABIs; the C++23 GCC 14 Release/maintainer executable passed all eight cases.