10000 Fix potential issue with WebWorker by Toflar · Pull Request #7539 · contao/contao · GitHub
[go: up one dir, main page]

Skip to content

Fix potential issue with WebWorker #7539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

Toflar
Copy link
Member
@Toflar Toflar commented Sep 19, 2024

Stacktrace:

ErrorException: Warning: proc_open(): Exec failed: Permission denied
#16 /vendor/symfony/console/Terminal.php(220): Symfony\Component\Console\Terminal::readFromProcess
#15 /vendor/symfony/console/Terminal.php(204): Symfony\Component\Console\Terminal::getSttyColumns
#14 /vendor/symfony/console/Terminal.php(170): Symfony\Component\Console\Terminal::initDimensionsUsingStty
#13 /vendor/symfony/console/Terminal.php(153): Symfony\Component\Console\Terminal::initDimensions
#12 /vendor/symfony/console/Terminal.php(94): Symfony\Component\Console\Terminal::getWidth
#11 /vendor/symfony/console/Style/SymfonyStyle.php(55): Symfony\Component\Console\Style\SymfonyStyle::__construct
#10 /vendor/symfony/messenger/Command/ConsumeMessagesCommand.php(136): Symfony\Component\Messenger\Command\ConsumeMessagesCommand::interact
#9 /vendor/symfony/console/Command/Command.php(311): Symfony\Component\Console\Command\Command::run
#8 /vendor/contao/core-bundle/src/Messenger/WebWorker.php(151): Contao\CoreBundle\Messenger\WebWorker::processTransport
#7 /vendor/contao/core-bundle/src/Messenger/WebWorker.php(67): Contao\CoreBundle\Messenger\WebWorker::onKernelTerminate
#6 /vendor/symfony/event-dispatcher/EventDispatcher.php(260): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}
#5 /vendor/symfony/event-dispatcher/EventDispatcher.php(220): Symfony\Component\EventDispatcher\EventDispatcher::callListeners
#4 /vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher::dispatch
#3 /vendor/symfony/http-kernel/HttpKernel.php(115): Symfony\Component\HttpKernel\HttpKernel::terminate
#2 /vendor/symfony/http-kernel/Kernel.php(157): Symfony\Component\HttpKernel\Kernel::terminate
#1 /vendor/symfony/http-kernel/HttpCache/HttpCache.php(262): Symfony\Component\HttpKernel\HttpCache\HttpCache::terminate
#0 /public/index.php(46): null

See inline comments for the explanation :)

Co-authored-by: Martin Auswöger <martin@auswoeger.com>
@fritzmg
Copy link
Contributor
fritzmg commented Sep 19, 2024

We could additionally check if the command is executed interactively and if not, not create a SymfonyStyle instance at all.

10000

@Toflar
Copy link
Member Author
Toflar commented Sep 19, 2024

Feel free to create that PR at Symfony explaining to them that they should not create a SymfonyStyle instance at all 🤣

@fritzmg
Copy link
Contributor
fritzmg commented Sep 20, 2024

Right, never mind, I missed that the command is not ours 🤦

@leofeyer leofeyer added this to the 5.3 milestone Sep 20, 2024
@leofeyer
Copy link
Member

But the Symfony phpDoc of the Terminal::getSttyColumns() explicitly says

Runs and parses stty -a if it's available, suppressing any error output.

So maybe we should report it there?

Comment on lines +169 to +170
putenv('COLUMNS='.$columnsBefore);
putenv('LINES='.$linesBefore);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will still be leakage while the command runs. And given that consuming messages can take longer, this is not an optimal solution. Is there really no other way to work around the problem?

@fritzmg
Copy link
Contributor
fritzmg commented Sep 20, 2024

But the Symfony phpDoc of the Terminal::getSttyColumns() explicitly says

Runs and parses stty -a if it's available, suppressing any error output.

So maybe we should report it there?

Yes, the suppressing any error output likely refers to the suppress_errors => true option of proc_open - however, that only applies to Windows.

Wouldn't

    private static function readFromProcess(string|array $command): ?string
    {
        if (!\function_exists('proc_open')) {
            return null;
        }

        $descriptorspec = [
            1 => ['pipe', 'w'],
            2 => ['pipe', 'w'],
        ];

        $cp = \function_exists('sapi_windows_cp_set') ? sapi_windows_cp_get() : 0;
+
-       $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);
+       $process = @proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);

        if (!\is_resource($process)) {
            return null;
        }

        $info = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        fclose($pipes[2]);
        proc_close($process);

        if ($cp) {
            sapi_windows_cp_set($cp);
        }

        return $info;
    }

be a better solution within Symfony?

// try/catch does not work for warnings here - using @ instead

@fritzmg
Copy link
Contributor
fritzmg commented Sep 20, 2024

See symfony/symfony#58332

@pressi
Copy link
Contributor
pressi commented Sep 20, 2024

But the Symfony phpDoc of the Terminal::getSttyColumns() explicitly says

Runs and parses stty -a if it's available, suppressing any error output.

So maybe we should report it there?

Yes, the suppressing any error output likely refers to the suppress_errors => true option of proc_open - however, that only applies to Windows.

Wouldn't

    private static function readFromProcess(string|array $command): ?string
    {
        if (!\function_exists('proc_open')) {
            return null;
        }

        $descriptorspec = [
            1 => ['pipe', 'w'],
            2 => ['pipe', 'w'],
        ];

        $cp = \function_exists('sapi_windows_cp_set') ? sapi_windows_cp_get() : 0;
+
-       $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);
+       $process = @proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);

        if (!\is_resource($process)) {
            return null;
        }

        $info = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        fclose($pipes[2]);
        proc_close($process);

        if ($cp) {
            sapi_windows_cp_set($cp);
        }

        return $info;
    }

be a better solution within Symfony?

// try/catch does not work for warnings here - using @ instead

👍 Würde bei mir auch funktionieren.
Sobald ich diese Zeile ändere steht im Log keine Meldung mehr.

Mache ich die Änderungen wieder rückgängig stehen sofort wieder die Fehler-Meldungen im Log.

@ausi
Copy link
Member
ausi commented Sep 29, 2024

As symfony/symfony#58332 was merged, do we still need this?

@Toflar
Copy link
Member Author
Toflar commented Sep 29, 2024

Nope, we can close :)

@Toflar Toflar closed this Sep 29, 2024
@Toflar Toflar deleted the fix/webworker-terminal-width branch September 29, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0