-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add shutdown strategy #547
Conversation
…p into add-shutdown-strategy (I merged master into remote add-shutdown-strategy by mistake - should have pulled locally)
use Bugsnag\Client; | ||
|
||
/** | ||
* Interface ShutdownStrategyInterface. |
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.
Worth expanding the docs here to describe the purpose of the interface and expected reasons for implementing it?
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.
It'd be worth adding a couple more tests, one to verify that the PhpShutdownStrategy
is used by default when no shutdownStrategy
is declared, and one to verify that the make
method of the client calls the constructor correctly and that the PhpShutdownStrategy
is used and the shutdown handler registered.
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 👍
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
Goal
We currently rely on register_shutdown_function() to defer calls to flush(). This potentially causes a memory leak as references to the Client are held until the script exits. (This is only an issue when testing with many instances of Client objects).
The call to register_shutdown_function is hardcoded in the constructor. This PR introduces a ShutdownStrategyInterface which replaces this hardcoding and allows for the injection of different shutdown strategies.
There is no functionality change in this PR. The current register_shutdown_function() behaviour is now wrapped inside an object. In a future PR on the bugsnag-symfony project I will introduce a Symfony-specific shutdown strategy that will fix issue-77.
Changeset
Added
Removed
Tests
Added unit tests. The "shutdownSpy" is a pretty cool way to test native functions (in this case the call to register_shutdown_function)
Discussion
Alternative Approaches
None.
Outstanding Questions
I think we should also make the call to registerShutdownStrategy conditional on whether we are in batch mode or not (there is no need to defer calls to flush() if we are not "batching"). However at this stage I want to change one thing at a time, so will potentially do this as a separate piece of work.
Review
For the submitter, initial self-review:
For the pull request reviewer(s), this changeset has been reviewed for: