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

Gracefully shutdown the agent if it encounters issues on startup #1136

Merged
merged 3 commits into from
Mar 1, 2023

Conversation

sdaubin
Copy link
Contributor

@sdaubin sdaubin commented Jan 30, 2023

If the java agent encounters a serious issue on startup, it calls System.exit. It would be better if it gracefully shutdown. This is a particularly troublesome quality when connecting to running applications.

I have a demo that connects to a Spring Petclinic app and uses the nri-lsi-java tool to connect the agent. It's causing the app to exit. Here's the repo: https://source.datanerd.us/saxon/java-agent-crash

Overview

This wraps the Instrumentation instance so that we can remove class transformers and shutdown the agent if there's an exception. We only do this for the attach (agentmain) case. premain works as it does today. When everyone is comfortable with this change it'd be nice to use it for premain as well.

Related Github Issue

https://issues.newrelic.com/browse/NR-84187

Testing

I've referenced a test repo to fully reproduce the issue. There are some unit tests for changes.

Checks

[] Are your contributions backwards compatible with relevant frameworks and APIs?
[ ] Does your code contain any breaking changes? Please describe.
[ ] Does your code introduce any new dependencies? Please describe.

@jasonjkeller
Copy link
Contributor

@sdaubin It looks like this new test is consistently failing on Java 11, 17, and 19:

com.newrelic.agent.util.UnwindableInstrumentationImplTest > getMissingInterfaceMethods FAILED
    java.lang.AssertionError at UnwindableInstrumentationImplTest.java:26

@jasonjkeller jasonjkeller merged commit 08819cd into newrelic:main Mar 1, 2023
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.

2 participants