-
Notifications
You must be signed in to change notification settings - Fork 34
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
Remove use of daemon threads, fixing potential resource leak #143
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…n sessionExecutorService
fractalwrench
changed the title
Remove use of daemon threads, fixing potential memory leak
Remove use of daemon threads, fixing potential resource leak
May 29, 2019
simonbowring
approved these changes
May 30, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
Incidentally, as a consequence of this PR and #121, in our example apps and test fixtures (I count 4 occurrences) we no longer need to do:
System.exit(SpringApplication.exit(...));
Instead we can just do this to exit an application without the application hanging:
SpringApplication.exit(...);
tomlongridge
added a commit
that referenced
this pull request
Nov 6, 2020
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. fixes #151
tomlongridge
added a commit
that referenced
this pull request
Nov 6, 2020
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. fixes #151
tomlongridge
added a commit
that referenced
this pull request
Nov 7, 2020
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. fixes #151
tomlongridge
added a commit
that referenced
this pull request
Nov 9, 2020
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. fixes #151
tomlongridge
added a commit
that referenced
this pull request
Nov 9, 2020
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
added a commit
that referenced
this pull request
Nov 9, 2020
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
added a commit
that referenced
this pull request
Nov 9, 2020
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Goal
Users have reported that daemon threads are not stopped when an application is stopped in a standalone Tomcat server. In an embedded server such as Spring Boot this does not matter as the JVM will always terminate when the application server is brought down, but in a standalone server, this can lead to threads leaking and performance problems over time.
We should fix this behaviour so that threads terminate properly when the application is shut down.
Changeset
DaemonThreadFactory
sessionExecutorService
to use a regular thread factory, whose threads will be stopped on application shutdownclose()
methodBugsnag
implementClosable
shutdownNow
on thesessionExecutorService
, as the periodic check to flush sessions is no longer needed when the application is terminating.Tests
Installed a standalone Tomcat server locally, and deployed a plain Spring application integrated with Bugsnag. Started then stopped the Tomcat server, and inspected the logs, verifying that there were no messages about thread leaks when this changeset was applied.
I also verified that the application shutdown when a crash occurred on startup, to verify that the scenario in #121 has not resurfaced.