-
Notifications
You must be signed in to change notification settings - Fork 33
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
[PLAT-2110] Use deamon threads to start flushing sessions #121
Conversation
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.
Left a few comments around the implementation, once resolved I'm happy to approve (after I perform manual testing again)
* This is to prevent applications from hanging waiting for the sessions scheduled task | ||
* because deamon threads will be terminated on application shutdown | ||
*/ | ||
public class DeamonThreadFactory implements ThreadFactory { |
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.
The implementation of this class could be simplified by using the decorator pattern. We could create a field for Executors.defaultThreadFactory()
, then make the thread returned by threadFactory.newThread
a daemon before returning. That might also make a good candidate for a unit test.
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.
changed
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.
also added a test
/** | ||
* @see ThreadFactory#newThread(Runnable) | ||
*/ | ||
public Thread newThread(Runnable runner) { |
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 is missing an override annotation
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.
Added
/** | ||
* Constructor | ||
*/ | ||
public DeamonThreadFactory() { |
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.
There's a typo in the class name (Deamon -> Daemon)
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.
fixed
// Create a new thread which is not a deamon thread to actually flush the sessions | ||
// This will means that the thread will not be killed | ||
// half way through if the application shuts down | ||
Thread nonDeamonThread = new Thread(new Runnable() { |
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.
We could use a cached executor e.g. Executors.newSingleThreadExecutor()
rather than creating a new thread every time this is invoked.
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.
Added new newSingleThreadExecutor
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.
LGTM - just needs a changelog entry.
This issue came up before with a single thread executor in #50 (current logic on master) - should the session flushing logic use an executor service in the same way to ensure the service doesn't hang an app? I'd just like to check that we aren't introducing a different way for the application to hang by fixing this one. |
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
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
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
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
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
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
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
Goal
In some cases the Bugsnag notifier can prevent clean application shutdowns due to the session flushing threads that are running.
This changes the threads to be marked as "deamon" so that the application can terminate without waiting for them to finish
The deamon threads run every 60 seconds to flush sessions created during that time. New threads are used to actually perform the flushing which are not marked as deamon so that they won't get killed part way though sending data.
Review
For the submitter, initial self-review:
For the pull request reviewer(s), this changeset has been reviewed for: