Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions library/Pdfexport/HeadlessChrome.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@

foreach ($arguments as $name => $value) {
if ($value !== null) {
$value = escapeshellarg($value);

Check failure on line 194 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #1 $arg of function escapeshellarg expects string, mixed given.

Check failure on line 194 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #1 $arg of function escapeshellarg expects string, mixed given.

Check failure on line 194 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #1 $arg of function escapeshellarg expects string, mixed given.

Check failure on line 194 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #1 $arg of function escapeshellarg expects string, mixed given.

if (! is_int($name)) {
if (substr($name, -1) === '=') {
Expand Down Expand Up @@ -247,18 +247,18 @@
*
* @return PromiseInterface
*/
public function asyncToPdf(): PromiseInterface

Check failure on line 250 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Method Icinga\Module\Pdfexport\HeadlessChrome::asyncToPdf() return type with generic interface React\Promise\PromiseInterface does not specify its types: T

Check failure on line 250 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Method Icinga\Module\Pdfexport\HeadlessChrome::asyncToPdf() return type with generic interface React\Promise\PromiseInterface does not specify its types: T

Check failure on line 250 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Method Icinga\Module\Pdfexport\HeadlessChrome::asyncToPdf() return type with generic interface React\Promise\PromiseInterface does not specify its types: T

Check failure on line 250 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Method Icinga\Module\Pdfexport\HeadlessChrome::asyncToPdf() return type with generic interface React\Promise\PromiseInterface does not specify its types: T
{
$deferred = new Promise\Deferred();
Loop::futureTick(function () use ($deferred) {
switch (true) {
case $this->remote !== null:
try {
$result = $this->jsonVersion($this->remote[0], $this->remote[1]);

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #2 $port of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects int, mixed given.

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #1 $host of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects string, mixed given.

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #2 $port of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects int, mixed given.

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #1 $host of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects string, mixed given.

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #2 $port of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects int, mixed given.

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #1 $host of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects string, mixed given.

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #2 $port of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects int, mixed given.

Check failure on line 257 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #1 $host of method Icinga\Module\Pdfexport\HeadlessChrome::jsonVersion() expects string, mixed given.
if (is_array($result)) {
$parts = explode('/', $result['webSocketDebuggerUrl']);

Check failure on line 259 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #2 $string of function explode expects string, mixed given.

Check failure on line 259 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #2 $string of function explode expects string, mixed given.

Check failure on line 259 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #2 $string of function explode expects string, mixed given.

Check failure on line 259 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #2 $string of function explode expects string, mixed given.
$pdf = $this->printToPDF(
join(':', $this->remote),

Check failure on line 261 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #2 $array of function join expects array<string>, array given.

Check failure on line 261 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #2 $array of function join expects array<string>, array given.

Check failure on line 261 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #2 $array of function join expects array<string>, array given.

Check failure on line 261 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #2 $array of function join expects array<string>, array given.
end($parts),
! $this->document->isEmpty() ? $this->document->getPrintParameters() : []
);
Expand Down Expand Up @@ -313,7 +313,7 @@
}

$killer = Loop::addTimer(10, function (TimerInterface $timer) use ($chrome, $deferred) {
$chrome->terminate(6); // SIGABRT
$this->terminateProcess($chrome, 6); // SIGABRT

Logger::error(
'Browser timed out after %d seconds without the expected output',
Expand All @@ -330,10 +330,10 @@

$chrome->start();

$chrome->stderr->on('data', function ($chunk) use ($chrome, $deferred, $killer) {

Check failure on line 333 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Cannot call method on() on React\Stream\ReadableStreamInterface|React\Stream\WritableStreamInterface|null.

Check failure on line 333 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Cannot call method on() on React\Stream\ReadableStreamInterface|React\Stream\WritableStreamInterface|null.

Check failure on line 333 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Cannot call method on() on React\Stream\ReadableStreamInterface|React\Stream\WritableStreamInterface|null.

Check failure on line 333 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Cannot call method on() on React\Stream\ReadableStreamInterface|React\Stream\WritableStreamInterface|null.
Logger::debug('Caught browser output: %s', $chunk);

if (preg_match(self::DEBUG_ADDR_PATTERN, trim($chunk), $matches)) {

Check failure on line 336 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #1 $string of function trim expects string, mixed given.

Check failure on line 336 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #1 $string of function trim expects string, mixed given.

Check failure on line 336 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #1 $string of function trim expects string, mixed given.

Check failure on line 336 in library/Pdfexport/HeadlessChrome.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #1 $string of function trim expects string, mixed given.
Loop::cancelTimer($killer);

try {
Expand All @@ -346,7 +346,7 @@
Logger::error('Failed to print PDF. An error occurred: %s', $e);
}

$chrome->terminate();
$this->terminateProcess($chrome);

if (! empty($pdf)) {
$deferred->resolve($pdf);
Expand Down Expand Up @@ -689,6 +689,26 @@
return $params;
}

/**
* Terminate a process and close pipes inherited by subprocesses
*
* Chrome spawns sub-processes that inherit open pipes. Close them before termination
* so the event loop is not kept alive by inherited file descriptors.
*
* @param Process $process The process to terminate
* @param ?int $signal The signal passed to Process::terminate()
*
* @return void
*/
private function terminateProcess(Process $process, ?int $signal = null): void
{
foreach ($process->pipes as $pipe) {
$pipe->close();
}

$process->terminate($signal);
}

/**
* Get the major version number of Chrome or false on failure
*
Expand Down
Loading