Skip to content
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

[Process] Process truncates output #9409

Closed
astephens25 opened this issue Oct 30, 2013 · 0 comments
Closed

[Process] Process truncates output #9409

astephens25 opened this issue Oct 30, 2013 · 0 comments
Labels

Comments

@astephens25
Copy link

When a process generates large amounts of output in a short time, the Process component can potentially ignore information which is buffered for reading. This appears to be because each readStreams() call reads only the first 8192 bytes of the data in the buffer for a particular pipe. I would expect that (on termination at least) all the remaining data is read from a pipe before closing.

This issue is also present if a single call to getOutput() is issued after the loop terminates. This issue becomes intermittent if the usleep() in the while loop below is omitted as a race condition is created between termination of the process and performing the next read.

This will only be present when generating large amounts of output. For programs which output less data, the number of calls to updateStatus() over the process lifetime will be sufficient to read all the output.

Code to reproduce:

$process = new Process('cat /etc/services');

$process->start();

while ($process->isRunning()) {
    echo $process->getIncrementalOutput();
    usleep(100);
}

echo $process->getIncrementalOutput();

As an experiment, I modified the readStreams() call in the ProcessPipes class to read using the following code:

$read[$type] = '';
while (strlen($data = fread($pipe, 8192)) > 0) {
    $read[$type] .= $data;
}

After this modification I was no longer able to reproduce the issue. I have not done a thorough investigation as to whether there is additional impact from a change such as this.

hkdobrev added a commit to despark/kohana that referenced this issue Feb 19, 2014
Move back to `post-create-project-cmd` event.

Bash expression for random salt is probably affected by:
symfony/symfony#9409

`cat /dev/urandom` outputs a very large amount of data.
Trying with external file
fabpot added a commit that referenced this issue Mar 12, 2014
…efore process termination (astephens25)

This PR was merged into the 2.3 branch.

Discussion
----------

[Process] Fixed data in pipe being truncated if not read before process termination

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9409
| License       | MIT
| Doc PR        | N/A

This is a repeat of the botched pull request #9630.

Commits
-------

7e51913 Fixed data in pipe being truncated if not read before process termination
@fabpot fabpot closed this as completed Mar 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants