10000 [Process] Fix process status tracking · symfony/symfony@6a9a305 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a9a305

Browse files
[Process] Fix process status tracking
1 parent 54b61d4 commit 6a9a305

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ jobs:
130130
echo SYMFONY_REQUIRE=">=$([ '${{ matrix.mode }}' = low-deps ] && echo 5.4 || echo $SYMFONY_VERSION)" >> $GITHUB_ENV
131131
[[ "${{ matrix.mode }}" = *-deps ]] && mv composer.json.phpunit composer.json || true
132132
133-
if [[ "${{ matrix.mode }}" = low-deps ]]; then
134-
echo SYMFONY_PHPUNIT_REQUIRE="nikic/php-parser:^4.18" >> $GITHUB_ENV
135-
fi
133+
echo SYMFONY_PHPUNIT_REQUIRE="nikic/php-parser:^4.18" >> $GITHUB_ENV
136134
137135
- name: Install dependencies
138136
run: |

src/Symfony/Component/Process/Process.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class Process implements \IteratorAggregate
8080
private WindowsPipes|UnixPipes $processPipes;
8181

8282
private ?int $latestSignal = null;
83-
private ?int $cachedExitCode = null;
8483

8584
private static ?bool $sigchild = null;
8685

@@ -1289,21 +1288,10 @@ protected function updateStatus(bool $blocking)
12891288
return;
12901289
}
12911290

1292-
$this->processInformation = proc_get_status($this->process);
1293-
$running = $this->processInformation['running'];
1294-
1295-
// In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call.
1296-
// Subsequent calls return -1 as the process is discarded. This workaround caches the first
1297-
// retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior.
1298-
if (\PHP_VERSION_ID < 80300) {
1299-
if (!isset($this->cachedExitCode) && !$running && -1 !== $this->processInformation['exitcode']) {
1300-
$this->cachedExitCode = $this->processInformation['exitcode'];
1301-
}
1302-
1303-
if (isset($this->cachedExitCode) && !$running && -1 === $this->processInformation['exitcode']) {
1304-
$this->processInformation['exitcode'] = $this->cachedExitCode;
1305-
}
1291+
if ($this->processInformation['running'] ?? true) {
1292+
$this->processInformation = proc_get_status($this->process);
13061293
}
1294+
$running = $this->processInformation['running'];
13071295

13081296
$this->readPipes($running && $blocking, '\\' !== \DIRECTORY_SEPARATOR || !$running);
13091297

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,10 @@ public function testProcessIsSignaledIfStopped()
712712
$this->markTestSkipped('Windows does not support POSIX signals');
713713
}
714714

715-
$process = $this->getProcessForCode('sleep(32);');
715+
$process = $this->getProcess(['sleep', '32']);
716716
$process->start();
717717
$process->stop();
718+
var_dump($process);
718719
$this->assertTrue($process->hasBeenSignaled());
719720
$this->assertEquals(15, $process->getTermSignal()); // SIGTERM
720721
}

0 commit comments

Comments
 (0)
0