-
Notifications
You must be signed in to change notification settings - Fork 324
Use destructor to close session (partially reverted #348) #412
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
Conversation
Well, I re-checked it, and it seems that I looked at the wrong test run when opening this PR. I guess the problem is with registering shutdown function. When you boot many kernels in a big test suite it register this function every time, wasting up memory. I think we need a config option to optionally enable/disable registering shutdown function. I'll update this PR tomorrow with such implementation. |
Seems related to #400? But isn't the root cause of this (and that) problem that you're actually trying to execute all those tests in the same process, which is something that PHP is really not meant to do given the whole existence of functions like I'm curious whether your issues are solved if you run phpunit with Keep in mind that we will likely not consider it wise to change/break perfectly fine code for web request handling scenarios just to facilitate unit tests, if the tests can be easily fixed by configuration or annotations that were invented for this precise purpose. |
We could maybe merge this and then enable the register_shutdown_function behavior only when locking is enabled. Without locking, a request timing out/failing probably shouldn't write the session data anyway. The problem when locking is that you end up with a session deadlock and block other requests for a while. Then in your test you can at least disable locking to make sure you avoid the memory leak. Process isolation is a solution but it also makes tests super slow.. |
Possibly more practical approach: we could use |
Yes.. or just making the register_shutdown_function optional with a constructor argument, then it's easy to toggle on/off. Because down the line this is a bad idea, it prevents writing app servers for example without leaking memory. |
Quick fix for 2.1 could also be to introduce some static behaviors, pseudocode:
|
I don't know how much this helps, it'll still keep a handle to every instance created so that leaks all the same IMO. |
Mmm true. So we should likely merge this and keep the |
@curry684 Thanks for the tip about As suggested by @Seldaek, register_shutdown_function should only be enabled when session locking is enabled.
into RedisSessionHandler constructor. |
That indicates your tests depend on order of execution and/or other tests to succeed, which is considered bad practice. Interdependency should be handled with
Fine with me, looks harmless enough and I'll merge it as it's a quick workaround for now. |
For the record: holding off on merge until that addition is made. |
Also #400 is a slightly different problem that we're not solving now. Could we do that in a practical way? |
Merged, thanks! |
Wanted just to share here my experience with session locking and Redis. As a solution we have used: pcntl_async_signals(true);
pcntl_signal(SIGTERM, static function () {
exit;
}); That installs a signal handler for the This implementation has as side effect that the worker process does not terminate on Fortunately when PHP-FPM scales down the workers, it uses SIGQUIT, so is able to free memory. Does anyone have an idea on how to handle this in a better way? |
@goetas The Symfony Lock component may have fixed this problem a better way? |
@B-Galati I do not think that is possible as locking issues are caused by phpfpm killing the process without calling destructors |
Registering a shutdown function to close session in PR #348 was a great idea... However removing a destructor was a terrible one.
We have a pretty heavy test suite in our app and after updating to SncRedisBundle v2.1 (which included that PR) memory usage in it just skyrocketed, PHP started crashing running out of memory.
This PR adds destructor back while also keeping a shutdown function introduced in #348. It solves the memory issue we're facing.