Move ShutdownHelper to agent-bootstrap… #3913
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…to avoid having to inject it into the bootstrap classloader later on.
Types under agent-bootstrap are automatically made available from the bootclasspath as part of installing the javaagent.
This avoids the need to register them as helper classes via HelperInjector. It is especially important to avoid using HelperInjector when instrumentating JDK classes because the only way we can inject types into the bootclasspath after the javaagent has been installed is to use a temporary jar file (unfortunately the only approach allowed by the JVM's instrumentation API)
Use of a temporary jar file causes issues in serverless environments, but it's worse when instrumenting j.l.Shutdown because we use File.deleteOnExit to attempt to clean up these temporary jars when the process ends (we cannot remove them while the JVM is alive because of how the JVM maps the classes into memory) and File.deleteOnExit interacts with j.l.Shutdown to register its own shutdown hook.
This results in an exception while trying to inject the helper
which then leads to the following exception at shutdown: