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

[BUG]: Logger stream with php://stdout is stuck when the output in the same file #16546

Open
eh0tka opened this issue Mar 14, 2024 · 0 comments
Labels
bug A bug report status: unverified Unverified

Comments

@eh0tka
Copy link

eh0tka commented Mar 14, 2024

Bug description
If there are more than one script use in the Logger stream to "php://stdout" and both scripts run within CLI having the output into the same place ( php script.php > /dev/null or > /path/to/file.log) then one of the script becomes stuck.

It wasn't an issue with Phalcon4 and PHP 7.4 but after upgrade to Phalcon5.6 and PHP 8.2 it took a lot to identify why my queue workers are being stuck

To Reproduce

  1. Write a simple infinite loop logger with while(true)
  2. Launch them in parallel with the output into the same file on the disk
  3. Watch the file with debug printing: it has some "NULNULNULNUL...." string and the output is almost taken but one of the worker while there is no printing from the second worker script

Steps to reproduce the behavior:

use Phalcon\Logger\Logger;
use Phalcon\Logger\Adapter\Stream as LoggerStreamAdapter;

$adapters['stdout'] = new LoggerStreamAdapter('php://stdout');

$logger = new Logger('messages', $adapters);

$num = $argv[1];

while (true) {
    $logger->info('I am here ' . $num);
    $logger->info('I am here again ' . $num);
    sleep(1);
}

Then we should launch via cli both scripts like:
php worker.php 1 > 1.log
php worker.php 2 > 1.log

NULLNULLNULLNULLNULLNULLNULL
��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������[2024-03-14T11:45:52+00:00][INFO] I am here 1
[2024-03-14T11:45:52+00:00][INFO] I am here again 1
[2024-03-14T11:45:53+00:00][INFO] I am here 1
[2024-03-14T11:45:53+00:00][INFO] I am here again 1
[2024-03-14T11:45:54+00:00][INFO] I am here 1
[2024-03-14T11:45:54+00:00][INFO] I am here again 1
[2024-03-14T11:45:55+00:00][INFO] I am here 1
[2024-03-14T11:45:55+00:00][INFO] I am here again 1
[2024-03-14T11:45:56+00:00][INFO] I am here 1
[2024-03-14T11:45:56+00:00][INFO] I am here again 1
[2024-03-14T11:45:57+00:00][INFO] I am here 1
[2024-03-14T11:45:57+00:00][INFO] I am here again 1
[2024-03-14T11:45:58+00:00][INFO] I am here 1

Expected behavior
We expect to see printing of both 1 & 2 workers but not only one.
If we replace stream php://stdout with "echo" it works better and both printings are visible.

Details

  • Phalcon version: 5.6.1
  • PHP Version: 8.2.16
  • Operating System: Debian 12
  • Installation type: installing via package manager & compiling from source, same
  • Zephir version (if any):??
  • Server: Just command line

Additional context
No matter where you push stream: into the /path/to/file.log or /dev/null if this is the same output location one of the script is blocked forever on $logger->info line and never goes further

@eh0tka eh0tka added bug A bug report status: unverified Unverified labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: unverified Unverified
Projects
None yet
Development

No branches or pull requests

1 participant