Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpCache] Unlink tmp file on error #26727

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

Merged
merged 1 commit into from
Apr 1, 2018
Merged

Conversation

Chansig
Copy link
Contributor

@Chansig Chansig commented Mar 31, 2018

Q A
Branch? 2.7 up to 4.0 for bug fixes
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #22719
License MIT
Doc PR

The tempnam function creates a unique temporary file for each call to a page to be cached, and if the temporary folder passed as an argument is not writable, tempnam will use /tmp.

Note: If PHP cannot create a file in the specified dir parameter, it falls back on the system default. On NTFS this also happens if the specified dir contains more than 65534 files.
http://php.net/manual/en/function.tempnam.php

Therefore, as soon as the HttpCache cache is no longer writable, the /tmp fills up fairly quickly, tempnam being called on every page (since no page cache) and creating a new unique file in /tmp.

See #22719

@@ -387,16 +387,22 @@ private function save($key, $data)

$tmpFile = tempnam(dirname($path), basename($path));
if (false === $fp = @fopen($tmpFile, 'wb')) {
@unlink($tmpFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot unlink an opened file on Windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the file is not open when fopen returns false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's quite possible :)

@fabpot
Copy link
Member

fabpot commented Apr 1, 2018

Thank you @Chansig.

@fabpot fabpot merged commit c9a0355 into symfony:2.7 Apr 1, 2018
fabpot added a commit that referenced this pull request Apr 1, 2018
This PR was merged into the 2.7 branch.

Discussion
----------

[HttpCache] Unlink tmp file on error

| Q             | A
| ------------- | ---
| Branch?       |  2.7 up to 4.0 for bug fixes <!-- see below -->
| Bug fix?      | yes
| New feature?  |no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #22719   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        |
<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

The tempnam function creates a unique temporary file for each call to a page to be cached, and if the temporary folder passed as an argument is not writable, tempnam will use /tmp.

_Note: If PHP cannot create a file in the specified dir parameter, it falls back on the system default. On NTFS this also happens if the specified dir contains more than 65534 files.
http://php.net/manual/en/function.tempnam.php_

Therefore, as soon as the HttpCache cache is no longer writable, the /tmp fills up fairly quickly, tempnam being called on every page (since no page cache) and creating a new unique file in /tmp.

See #22719

Commits
-------

c9a0355 [HttpCache] Unlink tmp file on error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants