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
Removed DaemonThreadFactory
Updated sessionExecutorService to use a regular thread factory, whose threads will be stopped on application shutdown
Refactored all shutdown logic to a close() method
Made Bugsnag implement Closable
Called shutdownNow on the sessionExecutorService, 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.
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.