Skip to content

[Process] Orphan temporary files are left on Windows #7078

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

Closed
extesy opened this issue Feb 15, 2013 · 7 comments
Closed

[Process] Orphan temporary files are left on Windows #7078

extesy opened this issue Feb 15, 2013 · 7 comments
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) Process

Comments

@extesy
Copy link

extesy commented Feb 15, 2013

On Windows Process::start creates a temporary file every time because of this code:

        if (defined('PHP_WINDOWS_VERSION_BUILD')) {
            $this->fileHandles = array(
                self::STDOUT => tmpfile(),
            );

When being invoked for thousands of times as part of task scheduling pipeline, it leaves thousands of temporary files and eventually hits the limit at 65536 files per directory, after which point it can't create a new temporary file and simply dies.

After being used, the temporary file should be deleted.

@jakzal
Copy link
Contributor

jakzal commented Feb 15, 2013

@extesy could you provide a failing test or an example code revealing the issue? Technically files should be automatically removed when fclose() is called or script finishes.

@extesy
Copy link
Author

extesy commented Feb 16, 2013

@jakzal It's quite hard to isolate the small repro case, but here's what I think is going on:

  1. Task runner process (the one which spawns worker processes) is always running, so it won't remove temp files because of "script finishes" condition.
  2. The only two places where fileHandles are closed are stop function which I don't use, and processFileHandles which has its $closeEmptyHandles parameter always set to false so it doesn't close handles either.

@extesy
Copy link
Author

extesy commented Feb 16, 2013

Actually, processFileHandles is not even being called. I pass $stdin=null to Process constructor and this code does an early return from the start function:

        if (null === $this->stdin) {
            fclose($this->pipes[0]);
            unset($this->pipes[0]);

            return;
        }

So fclose on fileHandles is not even called anywhere in the code path.

@theoreticaLee
Copy link

@extesy what are the exit statuses of these worker processes?

@fabpot
Copy link
Member

fabpot commented Aug 17, 2013

@romainneutron Can you have a look at this?

@romainneutron
Copy link
Contributor

@extesy @mirkin Can you provide a test script that reproduce the issue systematically ?

I do not have Windows OS. I tried to reproduce your issue by using file handles explicitely without success, temporary files are removed on process destruction.

@extesy
Copy link
Author

extesy commented Aug 17, 2013

Ok, I'll try to repro it with a test script.

fabpot added a commit that referenced this issue Sep 7, 2013
This PR was squashed before being merged into the 2.2 branch (closes #8924).

Discussion
----------

[Process][2.2] Fix Process component on windows

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8836, #8799, #7078
| License       | MIT

This PR fixes Process on windows (almost, see note below).
 - Some unit tests were not Windows compatible
 - Use a file handle for STDERR as well as STDOUT to avoid blocking
 - Decouple pipes and descriptors from Process

As this move some a part of Process in a sub class, I hope merging this in 2.3 and master would not be a PITA. I'm here to make some adjustments after theses merge if needed.

**Important note** :

We are using file handles instead of streams for `proc_open` pipes as described in the code (see [PHP bug #51800](https://bugs.php.net/bug.php?id=51800)). Unfortunately, this workaround may produce corrupted output/error output in some race conditions. That's why `AbstractProcessTest::testProcessPipes` randomly fails when using file handles (on unix and windows).

Commits
-------

4a76c76 [Process][2.2] Fix Process component on windows
@fabpot fabpot closed this as completed Sep 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) Process
Projects
None yet
Development

No branches or pull requests

5 participants