1010use React \EventLoop \StreamSelectLoop ;
1111use React \Socket \ConnectionInterface ;
1212use React \Socket \TcpServer ;
13+ use Rector \Caching \Detector \ChangedFilesDetector ;
1314use Rector \Core \Configuration \Option ;
1415use Rector \Core \Configuration \Parameter \ParameterProvider ;
1516use Rector \Core \Console \Command \ProcessCommand ;
2425use Symplify \EasyParallel \Enum \Content ;
2526use Symplify \EasyParallel \Enum \ReactCommand ;
2627use Symplify \EasyParallel \Enum \ReactEvent ;
28+ use Symplify \EasyParallel \ValueObject \ChildProcessTimeoutException ;
2729use Symplify \EasyParallel \ValueObject \ParallelProcess ;
2830use Symplify \EasyParallel \ValueObject \ProcessPool ;
2931use 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