Skip to content

Commit ebe779c

Browse files
committed
Parallel - process timeout made configurable
1 parent bc5c80a commit ebe779c

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

conf/config.neon

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ parameters:
4040
reportStaticMethodSignatures: false
4141
parallel:
4242
jobSize: 20
43+
processTimeout: 60.0
4344
polluteScopeWithLoopInitialAssignments: true
4445
polluteScopeWithAlwaysIterableForeach: true
4546
polluteCatchScopeWithTryAssignments: false
@@ -148,7 +149,8 @@ parametersSchema:
148149
reportMaybesInMethodSignatures: bool()
149150
reportStaticMethodSignatures: bool()
150151
parallel: structure([
151-
jobSize: int()
152+
jobSize: int(),
153+
processTimeout: float()
152154
])
153155
polluteScopeWithLoopInitialAssignments: bool()
154156
polluteScopeWithAlwaysIterableForeach: bool()
@@ -377,6 +379,7 @@ services:
377379
class: PHPStan\Parallel\ParallelAnalyser
378380
arguments:
379381
internalErrorsCountLimit: %internalErrorsCountLimit%
382+
processTimeout: %parallel.processTimeout%
380383

381384
-
382385
class: PHPStan\Parallel\Scheduler

src/Parallel/ParallelAnalyser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ class ParallelAnalyser
2323
/** @var int */
2424
private $internalErrorsCountLimit;
2525

26+
/** @var float */
27+
private $processTimeout;
28+
2629
/** @var ProcessPool */
2730
private $processPool;
2831

2932
public function __construct(
3033
IgnoredErrorHelper $ignoredErrorHelper,
31-
int $internalErrorsCountLimit
34+
int $internalErrorsCountLimit,
35+
float $processTimeout
3236
)
3337
{
3438
$this->ignoredErrorHelper = $ignoredErrorHelper;
3539
$this->internalErrorsCountLimit = $internalErrorsCountLimit;
40+
$this->processTimeout = $processTimeout;
3641
}
3742

3843
/**
@@ -120,7 +125,7 @@ public function analyse(
120125
$serverPort,
121126
$processIdentifier,
122127
$input
123-
), $loop);
128+
), $loop, $this->processTimeout);
124129
$process->start(function (array $json) use ($process, &$internalErrors, &$errors, &$jobs, $postFileCallback, &$hasInferrablePropertyTypesFromConstructor, &$internalErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier): void {
125130
foreach ($json['errors'] as $jsonError) {
126131
if (is_string($jsonError)) {

src/Parallel/Process.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Process
1919
/** @var LoopInterface */
2020
private $loop;
2121

22+
/** @var float */
23+
private $timeoutSeconds;
24+
2225
/** @var WritableStreamInterface */
2326
private $in;
2427

@@ -39,11 +42,13 @@ class Process
3942

4043
public function __construct(
4144
string $command,
42-
LoopInterface $loop
45+
LoopInterface $loop,
46+
float $timeoutSeconds
4347
)
4448
{
4549
$this->command = $command;
4650
$this->loop = $loop;
51+
$this->timeoutSeconds = $timeoutSeconds;
4752
}
4853

4954
public function start(callable $onData, callable $onError, callable $onExit): void
@@ -103,9 +108,9 @@ public function request(array $data): void
103108
{
104109
$this->cancelTimer();
105110
$this->in->write($data);
106-
$this->timer = $this->loop->addTimer(60.0, function (): void {
111+
$this->timer = $this->loop->addTimer($this->timeoutSeconds, function (): void {
107112
$onError = $this->onError;
108-
$onError(new \Exception('Child process timed out after 60 seconds.'));
113+
$onError(new \Exception(sprintf('Child process timed out after %.1f seconds.', $this->timeoutSeconds)));
109114
});
110115
}
111116

0 commit comments

Comments
 (0)