Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix lifetime of GlobalLogHandler #3221

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

owent
Copy link
Member

@owent owent commented Dec 24, 2024

Fixes #3215

Changes

  • Keep the lifetime of GlobalLogHandler when calling OTEL_INTERNAL_LOG_*.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

Copy link

netlify bot commented Dec 24, 2024

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 2245d89
🔍 Latest deploy log https://app.netlify.com/sites/opentelemetry-cpp-api-docs/deploys/677de8f17f2ff400084cdae9

Copy link

codecov bot commented Dec 24, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.15%. Comparing base (3b89346) to head (2245d89).

Files with missing lines Patch % Lines
...lude/opentelemetry/sdk/common/global_log_handler.h 81.82% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3221      +/-   ##
==========================================
- Coverage   88.16%   88.15%   -0.00%     
==========================================
  Files         198      198              
  Lines        6224     6236      +12     
==========================================
+ Hits         5487     5497      +10     
- Misses        737      739       +2     
Files with missing lines Coverage Δ
sdk/src/common/global_log_handler.cc 77.42% <100.00%> (+6.59%) ⬆️
...lude/opentelemetry/sdk/common/global_log_handler.h 64.00% <81.82%> (-1.00%) ⬇️

{
return GetHandlerAndLevel().first;
if OPENTELEMETRY_UNLIKELY_CONDITION (GetHandlerAndLevel().destroyed)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I interpret the standard correctly, this may be an undefined behavior.

[basic.life] says that "[t]he lifetime of an object o of type T ends when: <...> if T is a class type, the destructor call starts", and "after the lifetime of an object has ended and before the storage which the object occupied is reused or released, any pointer that represents the address of the storage location where the object will be or was located may be used but only in limited ways. <...> The program has undefined behavior if: <...> the pointer is used to access a non-static data member or call a non-static member function of the object".

Copy link
Member Author

@owent owent Jan 8, 2025

Choose a reason for hiding this comment

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

Yes, it's a trick that the memory address of a static local variable will always be available in practice. So we can visit it even if it's destructed.

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.

Garbage pointer dereference when using OTLP GRPC exporter with inacessible endpoint
2 participants