-
Notifications
You must be signed in to change notification settings - Fork 850
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
Race condition in SDK shutdown #6827
Comments
thanks for posting the repro! I believe this is a limitation to running the shutdown hook inside of the maven process, I think we've seen the same issue here: open-telemetry/opentelemetry-java-contrib#990 and I can reproduce it without even loading the SDK with just:
and running while given that this has been reported a couple of times, it may be worth catching |
I'd welcome a PR with this proposal |
@trask do you have a trick for detecting if we're running inside of maven? My instinct is to check for a class, but if the classpath is being torn down can that be reliable? Some other way? |
you could check for a maven class in static init (at startup) and store into static boolean that could be referenced from shutdown hook |
Describe the bug
In some circumstances, after successful execution of an instrumented program, an exception is thrown on termination:
Steps to reproduce
I am not sure how reliable my repro, but I hope maybe Docker makes it more stable.
https://github.com/greatvovan/otel-log4j-file-config/tree/bug/class-not-found
This reliably throws exception every time for me.
Originally I discovered the error in the following way. I have this example for Log4j Appender:
https://github.com/greatvovan/otel-log4j-file-config/tree/bug/repro-runtime-hook
(Note that
OTEL_LOGS_EXPORTER
is set toconsole
for this one).It works fine, but if I comment the rows for
OpenTelemetryAppender
in log4j2.xml, the error appears. As from the semantics perspective it makes absolutely no sense, I conclude that it may be related to the order or timing of how the library cleans up the resources on program exit.If I change the shutdown hook to a synchronous call to
openTelemetry.shutdown();
it solves the problem but it postsI think it is the least of the evils, as it's either an info message or nothing.
What did you expect to see?
No weird exceptions.
What did you see instead?
A confusing exception.
What version and what artifacts are you using?
Artifacts: sdk, Console Exporter
Version: (e.g., 1.43.0 or bom 2.9.0)
How did you reference these artifacts? pom.xml
Environment
Compiler: Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OS: Ubuntu 24.04.1 LTS
Runtime (if different from JDK above): "21.0.4" 2024-07-16 LTS
Additional context
I found the exception harmless, but it is very confusing for the user to see it, because it leads to internals of the library and makes one think something is wrong with instrumentation. Also it complains on the class that 100% exists in the class path (the line
import io.opentelemetry.sdk.common.CompletableResultCode
succeeds in run time), which can make user think some dependencies are missing while it is not like that.The text was updated successfully, but these errors were encountered: