-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Fix memory limit problems in BinaryFileResponse #48972
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
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Thanks for the PR. Can you please add a test case? |
I tried to have a look on a reproduction and a test case. I can add a test, that chunks are used with my changes, but I failed in reproducing hitting memory_limit. I analyzed, why it happened in our application and found that there were two levels of output buffering. Closing both/all (instead of just one) did work well for us. So my findings are:
So my PR is not valid for all cases, as developer I would have expected either closing all output buffers internally via
or just throw an exception, if there is any output buffer active. For me it would help to see this dependency somehow, when using BinaryFileResponse. Its just not visible, that the file fully is loaded to memory instead of sent until you hit a file that does not fit in your memory limit. |
I thought about this some days now. Closing all output-buffers (via while) is possible in our specific case, so we need not to wait for this PR, but indeed especially for end-to-end functional tests it would be nice to be able to keep at least one buffer open in order to be able to check the content of the binary file response. In the test case, it will not exceed the memory limit. To change the code from -1 to $filesize would support this. In this case we would be able to close our one "known" buffer that catches all for some other reasons, but still would allow to put any code around it with separate handling like a test that checks a buffer afterwards. I will check, if I can add testcases in order to demonstrate this. |
Thank you @glady. |
see #48692