-
Notifications
You must be signed in to change notification settings - Fork 438
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
Segfault when MetricProvider tries to log to already destructed global log handler at exit #1718
Comments
Here is a backtrace:
|
Thanks for the details. I think it would be safe to silently drop the warning when the MeterProvider::Shutdown() is called twice ( the second one through it's destructor), or atleast don't rely on the global log handler to log the error - opentelemetry-cpp/sdk/src/metrics/meter_context.cc Lines 84 to 87 in dd7e257
|
Could you debug the codes in meter_context.cc:86 to find why |
|
Maybe we can add a wrapper and set the guard flag to |
Correct me, but that would mean there would be an atomic check to this guard flag everytime the log-macros are called. |
I think we can just use a normal variable, but not a atomic. We just need to check if the memory can be access. But it may be warned by tsan. |
Thanks @owent , I just used another approach in #1767 to control the order of construction and destruction. Though it is merged, let me know if you see any issues with that approach. |
When using the SDK
MeterProvider::Shutdown
explicitly beforestd::exit
without having any log messages before setting the globalMeterProvider
, the global log handler seems to get destructed before theMeterProvider
during cleanup of static storage duration variables.The below program is a minimal reproducible example, which you may need to run a few times (although in GDB I seem to always hit the segfault).
If I put breakpoints on the destructor of the log handler, I see it getting destructed before the
MeterProvider
.Not sure what a good fix would be, but this occurs if
Shutdown
is called twice. If users are not intended to call the SDKMeterProvider::Shutdown
function explicitly, perhaps it should not be public.Another option may be to make the logger instance non-local to
GlobalLogHandler::GetHandlerAndLevel
such that it is always initialized before users callSetMeterProvider
. I don't know what other static storage duration things may log during destruction, but if more instances of this problem exist, that would also fix those.To reproduce:
The text was updated successfully, but these errors were encountered: