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

ApplicationInsights-Java having issues with Tomcat Shutdown. #712

Closed
sudhanshu20 opened this issue Jul 31, 2018 · 6 comments
Closed

ApplicationInsights-Java having issues with Tomcat Shutdown. #712

sudhanshu20 opened this issue Jul 31, 2018 · 6 comments
Assignees

Comments

@sudhanshu20
Copy link

Expected behavior

All open threads by ApplicationInsights close gracefully while Tomcat shuts down.

Actual behavior

Tomcat 8.5 shutdown gets stuck while probably closing threads started by appinsights filter. This creates issues with Jenkins application auto build and deploy.
Removing the filter lets tomcat shutdown gracefully.

Attached shutdown log of tomcat which get stuck and does not respond.

appinsights_issue.txt

@dhaval24
Copy link
Contributor

@sudhanshu20 could you please provide the way you are instrumenting your application.

Also what kind of application are you having. Could you please provide details. Also please turn on SDK logs and provide us with those also.

@sudhanshu20
Copy link
Author

@dhaval24 Its REST based api using Spring MVC and we are instrumenting the application using ApplicationInsights.xml instrumentationkey. The logging to the portal has no issues and we can access the logs via portal. The problem is with Tomcat Shutdown/Restart after the introduction of the app insights filter. What specific logs are you looking from the application?

@dhaval24
Copy link
Contributor

dhaval24 commented Aug 4, 2018

@sudhanshu20 I am looking for the Application Insights SDK logs to see if the SDK is behaving wierdly. You can turn SDK logs on by <SDKLogger /> adding this tag in your applicationinsights.xml

@sudhanshu20
Copy link
Author

@dhaval24 Please find attached startup and shutdown log with AI SDK logs turned on. I have removed some app specific information from the logs. It seems the AI beat is still active while shutdown and tomcat is not able to kill it? Please let me know in case you need more info.
startup-tomcat-AI.txt
shutdown-tomcat-AI.txt

@littleaj
Copy link
Contributor

littleaj commented Aug 7, 2018

@sudhanshu20 , There is a ServletContextListener which triggers the shutdown of the Application Insights thread pools. For spring-boot, it appears the application needs an additional annotation to find this listener, e.g. @ServletComponentScan("com.microsoft.applicationinsights.web.internal"). I noticed in the shutdown logs that I did not see Shutting down thread pools in the logs which is printed by the listener.

Here's an article with more general information about the spring-boot annotation: https://www.baeldung.com/spring-servletcomponentscan

Let us know if this is a sufficient workaround. We're investigating ways for this to be picked up without additional configuration.

For our reference, is this packaged as a WAR or JAR?

(for our records: #568, #513)

@sudhanshu20
Copy link
Author

sudhanshu20 commented Aug 8, 2018

@littleaj , @dhaval24 . Thanks for looking into the issue. The workaround worked!. I added the following listener in web.xml of the app and now server shutdown is smooth. FYI, it now prints the shutdown comment 'Shutting down thread pools' as well.

< listener >
< listener-class>com.microsoft.applicationinsights.web.internal.ApplicationInsightsServletContextListener
< /listener >
The app is packaged as a WAR. It is built (using maven) and deployed on tomcat 8.5 using jenkins.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants