Skip to content
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

symfony/console Unable to write output. #36166

Closed
robtesch opened this issue Mar 22, 2020 · 9 comments
Closed

symfony/console Unable to write output. #36166

robtesch opened this issue Mar 22, 2020 · 9 comments

Comments

@robtesch
Copy link

Symfony version(s) affected:v5.0.5

Description
#laravel/horizon#762
Several of us have been having bizarre issues when using Laravel Horizon to manage our background queues. Since the actual error stems from symfony/console (and there is a comment just above the exception in the source code that says it should never get there) I figured it was best to submit an issue here about it.

How to reproduce
Unfortunately this one is pretty tough to get to the bottom of. So far it seems pretty "random" as to what's causing it. The best lead we have to go down is, throw an exception of any kind during a queued job. Steps to get there are as follows:

  1. Install fresh copy of laravel v7.2.2 (although version seems to vary)
  2. Install latest version of laravel horizon (v4.0.2, but again, version seems to vary)
  3. Create a queued job that throws an exception (a RuntimeException for good measure).
  4. Run that job loads of times.
  5. In order to catch the bug, use Bugsnag for bug reporting.

Possible Solution
Tried many things in order to reproduce or fix and so far absolutely nothing has helped.

Additional context
Stack trace:

Symfony\Component\Console\Exception\RuntimeException · Unable to write output.
/home/forge/my.laravel-app.com/vendor/symfony/console/Output/StreamOutput.php:79Symfony\Component\Console\Output\StreamOutput::doWrite	
/home/forge/my.laravel-app.com/vendor/symfony/console/Output/Output.php:166Symfony\Component\Console\Output\Output::write	
/home/forge/my.laravel-app.com/vendor/symfony/console/Output/Output.php:132Symfony\Component\Console\Output\Output::writeln	
/home/forge/my.laravel-app.com/vendor/symfony/console/Style/OutputStyle.php:62Symfony\Component\Console\Style\OutputStyle::writeln	
/home/forge/my.laravel-app.com/vendor/symfony/console/Style/SymfonyStyle.php:375Symfony\Component\Console\Style\SymfonyStyle::writeln	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:186Illuminate\Queue\Console\WorkCommand::writeStatus	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:166Illuminate\Queue\Console\WorkCommand::writeOutput	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:143Illuminate\Queue\Console\WorkCommand::Illuminate\Queue\Console\{closure}	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:369Illuminate\Events\Dispatcher::Illuminate\Events\{closure}	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:218Illuminate\Events\Dispatcher::dispatch	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:524Illuminate\Queue\Worker::raiseAfterJobEvent	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:358Illuminate\Queue\Worker::process	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:306Illuminate\Queue\Worker::runJob	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:132Illuminate\Queue\Worker::daemon	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:112Illuminate\Queue\Console\WorkCommand::runWorker	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:96Illuminate\Queue\Console\WorkCommand::handle	
/home/forge/my.laravel-app.com/vendor/laravel/horizon/src/Console/WorkCommand.php:46Laravel\Horizon\Console\WorkCommand::handle	
[internal]call_user_func_array	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32Illuminate\Container\BoundMethod::Illuminate\Container\{closure}	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Container/Util.php:36Illuminate\Container\Util::unwrapIfClosure	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:90Illuminate\Container\BoundMethod::callBoundMethod	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:34Illuminate\Container\BoundMethod::call	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Container/Container.php:592Illuminate\Container\Container::call	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Console/Command.php:134Illuminate\Console\Command::execute	
/home/forge/my.laravel-app.com/vendor/symfony/console/Command/Command.php:255Symfony\Component\Console\Command\Command::run	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Console/Command.php:121Illuminate\Console\Command::run	
/home/forge/my.laravel-app.com/vendor/symfony/console/Application.php:912Symfony\Component\Console\Application::doRunCommand	
/home/forge/my.laravel-app.com/vendor/symfony/console/Application.php:264Symfony\Component\Console\Application::doRun	
/home/forge/my.laravel-app.com/vendor/symfony/console/Application.php:140Symfony\Component\Console\Application::run	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Console/Application.php:93Illuminate\Console\Application::run	
/home/forge/my.laravel-app.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:130Illuminate\Foundation\Console\Kernel::handle	
/home/forge/my.laravel-app.com/artisan:37[main]
@HarasimowiczKamil
Copy link

Problem is with PHP 7.4 https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.core.fread-fwrite
I have this same issue just on Symfony 4.3

@robtesch
Copy link
Author

Thanks for tracking this down @HarasimowiczKamil . I guess there still needs to be some change in the symfony component then so that it handles the new return differently?

@HarasimowiczKamil
Copy link

HarasimowiczKamil commented Mar 26, 2020

Yes https://github.com/symfony/console/blob/master/Output/StreamOutput.php#L77 "should never happen" just happened 😄 For now I use --quiet flag in cli tasks. I do not know what's the idea, do the developers want to remove the if or otherwise handle it?

@mfn
Copy link

mfn commented Mar 26, 2020

I've also experienced this, but nothing more of value to add her.

My "best guess": behaviour change in 7.4 now exposing something which was already there but hidden?

OP however didn't state PHP Version , @robtesch are you using PHP 7.4 ?

@robtesch
Copy link
Author

@mfn yes, sorry, at the time of posting i didn't know it was php version related, but yes, i am using PHP 7.4.

@JacobBennett
Copy link

Same here

fabpot added a commit that referenced this issue Mar 27, 2020
This PR was squashed before being merged into the 3.4 branch.

Discussion
----------

[Console] Fix OutputStream for PHP 7.4

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36166
| License       | MIT

From PHP 7.4, `fwrite` function now returns false for any failure: https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.core.fread-fwrite

Actually, the note in the PHP documentation is not exact: for PHP 7.3 and lower, `fwrite` function did return false when arguments passed in to the function were invalid, and 0 for other failures. From PHP 7.4, it returns false for any failure.
We can see it in the source code: for PHP 7.3: https://github.com/php/php-src/blob/a1a8d144854acb1c891cf0c21abb0f612b1d8de7/ext/standard/file.c#L1140
Compare to PHP 7.4: https://github.com/php/php-src/blob/master/ext/standard/file.c#L1136

I update `OutputStream::doWrite()` to keep the same behavior as before.

Commits
-------

b375f93 [Console] Fix OutputStream for PHP 7.4
@HarasimowiczKamil
Copy link

HarasimowiczKamil commented Apr 6, 2020

Is there a chance to merge to 4.3?

@xabbuh
Copy link
Member

xabbuh commented Apr 9, 2020

@HarasimowiczKamil Symfony 4.3 does not receive bugfixes anymore. You will need to update to 4.4 (see https://symfony.com/releases/4.3).

@KolyaSlisarenko
Copy link

KolyaSlisarenko commented Apr 6, 2021

I had the same issue on Laravel. Afther writing ps -aux | grep artisan I saw that there were so many processes:
root xxxx x.x x.x xxxxxx xxxxx ? S Apr02 0:00 php artisan tinker
I removed there processes by running kill <PROCESS_ID> and it solved my issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants