Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BinaryFileResponse deleteFileAfterSend on client abortion #27538

Copy link
Copy link
Closed
@TiMESPLiNTER

Description

@TiMESPLiNTER
Issue body actions

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.)

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php#L303

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.