Skip to content

Commit 7d71fe5

Browse files
committed
[cache] Clear files cached by worker process request if that request has timed out
1 parent 60b85e9 commit 7d71fe5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/Parallel/Application/ParallelFileProcessor.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use React\EventLoop\StreamSelectLoop;
1111
use React\Socket\ConnectionInterface;
1212
use React\Socket\TcpServer;
13+
use Rector\Caching\Detector\ChangedFilesDetector;
1314
use Rector\Core\Configuration\Option;
1415
use Rector\Core\Configuration\Parameter\ParameterProvider;
1516
use Rector\Core\Console\Command\ProcessCommand;
@@ -24,6 +25,7 @@
2425
use Symplify\EasyParallel\Enum\Content;
2526
use Symplify\EasyParallel\Enum\ReactCommand;
2627
use Symplify\EasyParallel\Enum\ReactEvent;
28+
use Symplify\EasyParallel\ValueObject\ChildProcessTimeoutException;
2729
use Symplify\EasyParallel\ValueObject\ParallelProcess;
2830
use Symplify\EasyParallel\ValueObject\ProcessPool;
2931
use Symplify\EasyParallel\ValueObject\Schedule;
@@ -46,7 +48,8 @@ final class ParallelFileProcessor
4648

4749
public function __construct(
4850
private readonly WorkerCommandLineFactory $workerCommandLineFactory,
49-
private readonly ParameterProvider $parameterProvider
51+
private readonly ParameterProvider $parameterProvider,
52+
private readonly ChangedFilesDetector $changedFilesDetector,
5053
) {
5154
}
5255

@@ -125,6 +128,18 @@ public function process(
125128
++$systemErrorsCount;
126129
$reachedSystemErrorsCountLimit = true;
127130
$this->processPool->quitAll();
131+
132+
// This sleep has to be here, because event though we have called $this->processPool->quitAll(),
133+
// it takes some time for the child processes to actually die, and if we would delete the offending cache
134+
// files right away, they could still write them "back" before they die
135+
sleep(1);
136+
if ($throwable instanceof ChildProcessTimeoutException) {
137+
$context = $throwable->getContext();
138+
139+
foreach ($context[Bridge::FILES] as $file) {
140+
$this->changedFilesDetector->invalidateFile($file);
141+
}
142+
}
128143
};
129144

130145
$timeoutInSeconds = $this->parameterProvider->provideIntParameter(Option::PARALLEL_JOB_TIMEOUT_IN_SECONDS);

0 commit comments

Comments
 (0)