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

fix: jvm hangs when System.exit or bugsnag.close is not called #157

Merged
merged 1 commit into from
Nov 9, 2020

Conversation

tomlongridge
Copy link
Contributor

@tomlongridge tomlongridge commented Nov 6, 2020

Goal

The fix to prevent a resource leak in #143 improved the shutdown hook to prevent the resource leak (calling ExceptionHandler.disable and config.delivery.close) but also reverted the task scheduler from running as a daemon thread. Therefore, in a console app, or similar, which doesn't explicitly call System.exit, the JVM waits indefinitely for the sessionExecutorService to stop before triggering the shutdown hook.

This PR should be the benefits of both #143 and #121 to gracefully shutdown in both use cases.

Fixes #151

Changeset

Testing

  • Updated the "mazerunner" (Spring boot app) end-to-end test to remove the System.exit call to test this in future.
  • Also ran the fix in a standalone Tomcat war to ensure the warnings about resource leaks were not seen.

@tomlongridge tomlongridge force-pushed the tom/fix-jvm-shutdown branch 3 times, most recently from 8e60dd1 to 01c6ea6 Compare November 9, 2020 09:53
@tomlongridge tomlongridge marked this pull request as ready for review November 9, 2020 09:56
* This is to prevent applications from hanging waiting for the sessions scheduled task
* because daemon threads will be terminated on application shutdown
*/
public class DaemonThreadFactory implements ThreadFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original PR had a test for this class which may be worth reinstating: https://github.com/bugsnag/bugsnag-java/pull/143/files

@tomlongridge tomlongridge changed the base branch from master to next November 9, 2020 11:36
The fix to prevent a resource leak in #143 removed the task scheduler running as
a daemon thread and so doesn't exit unless the application is explicitly exited
(via System.exit) or the thread is explicitly stopped (via bugsnag.close).

This fix should be the benefits of both #143 and #121 to gracefully shutdown in
both use cases.

Updated the Spring Boot app test and example to remove explict System.exit call
as this should not be required.

fixes #151
@tomlongridge tomlongridge merged commit 1dce87e into next Nov 9, 2020
@tomlongridge tomlongridge deleted the tom/fix-jvm-shutdown branch November 9, 2020 12:56
@tomlongridge tomlongridge mentioned this pull request Nov 9, 2020
@nullobject
Copy link

Nice 👏

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.

Bugsnag prevents JVM from shutting down normally
3 participants