Description
Symfony version(s) affected: ^3.4
Description
If I set deleteFileAfterSend
to true for a BinaryFileResponse
instance. The file only gets deleted if the response gets completely streamed to the client. If the client aborts before the whole content of the file has been streamed to the client the PHP script aborts and therefor the file does not get deleted. (PHP script aborts as soon as it tries and fails to stream to the pipe.)
How to reproduce
Return a large file using a BinaryFileResponse and set the deleteFileAfterSend
to true. Then abort during the download. The file will still be there.
Possible Solution
I'm not sure if this is a bug or not. Basically the file hasn't been completely sent to the client therefor one can argue that the file should not be deleted. However in our case we prefer the clean up part over the consistency part. Maybe a bit more granularity would help. (Something like deleteFileAfterSuccessfulSent
and deleteFileAfterRequest
.)
There is a ignore_user_abort()
function which could help solving this "issue". The question is if symfony wants to support that/take care of it or if it's in the responsibility of the controller to call the function before returning the response. (Which would not be that clean imho.)
What are your thoughts?