-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Avoid memory leak in HandleExceptions during repeated Application startup #44293
[9.x] Avoid memory leak in HandleExceptions during repeated Application startup #44293
Conversation
b1ec0cf
to
510fd2e
Compare
510fd2e
to
0bce18c
Compare
if (! static::$globalShutdownFunctionRegistered) { | ||
static::$globalShutdownFunctionRegistered = true; | ||
|
||
register_shutdown_function($this->forwardsTo('handleShutdown')); |
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.
Not ideal as it keeps reference to original $this but there is no way to unregister a shutdown function. To solve it properly, yet another layer of indirection with reference to $this
must be kept static (which pretty much makes the HandleExceptions class a singleton, which it already pretty much is 🤷♂️).
Needs a bit more thought.
744ceab
to
6dda8c0
Compare
6dda8c0
to
6db4dbf
Compare
Not a bullet-proof solution but it keeps the API, the behavior with PHPUnit should remain the same while the leak seems to be gone. The only issue is that the I understand that since the leak is pretty small, the changes here may not be worth it. The current behaviour leads people to look for bugs in the framework though and not their apps so perhaps that could be prevented. |
Closing this pull request for the reasons already mentioned here: #40656. TL DR: You can't safely restore any of those handlers (at least on the way you are), as they may be used on vendors (such as PHPUnit, and error handler drivers), and by calling any of those restores, you don't know exactly what you are restoring. In addition, leaking a small closure is not what causing the memory exhausted cases we've seen in past issues. The |
Partially resolves #44214.
Repeatedly running following script (which happens during PHPUnit test setup) slowly but steadily leaks memory since the
register_shutdown_function
is never released: