swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.42k stars 3.16k forks source link

Symfony/Process run (proc_open) timeouts after Swoole v4.6.5 executes #4162

Open anibalsanchez opened 3 years ago

anibalsanchez commented 3 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.

I have a PHP CLI that executes these classes in this order:

On Swoole v4.4.25, it works OK.

On Swoole Swoole v4.6.5 (and v4.5.11), the second time that the CLI calls the Symfony\Component\Process\Process the execution timeouts without executing.

  1. What did you expect to see?

The same execution results on v4.6.5 (or v4.5.11).

  1. What did you see instead?

The Process halts with a timeout.

Specifically, in the second time that the CLI calls the Symfony\Component\Process\Process, it is executed in a loop and at some point of the iteration the call to @proc_open hangs.

  1. What version of Swoole are you using (show your php --ri swoole)?
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.6.5
Built => Apr 21 2021 17:10:49
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
Linux mars 5.8.0-50-generic #56-Ubuntu SMP Mon Apr 12 17:18:36 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

PHP 7.4.9 (cli) (built: Oct 26 2020 15:17:14) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 10.2.0-13ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Ubuntu 10.2.0-13ubuntu1)
sy-records commented 3 years ago

Can you provide scripts for reproducible issues?

anibalsanchez commented 3 years ago

The issue is found on a system that can't be easily taken apart. I don't have a simple reproducible script.

Now, it is running on Swoole v4.4.25, but something is going on in the next versions.

It looks like after Swoole executes something is locked on proc_open and it waits forever. Let me know if there is a way to diagnose the issue.

twose commented 3 years ago

If you are using Linux, you can try to install strace and run your application by strace -f -o /tmp/strace.log xxx.php, when you reproduce the problem, you can cancel it and show the content of /tmp/strace.log here.

bmlkc commented 3 years ago

The issue might be this:

namespace Telesero\Telephony\Lib\Tests\Reproduce;

use PHPUnit\Framework\TestCase;
use Swoole\Coroutine;
use Swoole\Runtime;

class ProcHangTest extends TestCase
{

    public function testProcOpen()
    {
        Runtime::setHookFlags(SWOOLE_HOOK_ALL);
        Coroutine\run(
            function () {

                go(
                    function () {
                        $pipes = [];
                        $h = proc_open('sleep 10000', [], $pipes);
                        throw new \RuntimeException();
                    }
                );
            }
        );
    }
}

if your application throws an exception and if you started something that runs indefinitely with proc, your app never quits.

php 7.4.16 + swoole 4.6.6

bmlkc commented 3 years ago

Another symfony issue I figured is booting kernel in a coro:

<?php

namespace Telesero\Telephony\Lib\Tests\Reproduce;

use Swoole\Coroutine;
use Swoole\Runtime;

class InsideCoroKernelBootTest extends \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
{

    public function testBoot()
    {
        Runtime::setHookFlags(SWOOLE_HOOK_ALL);
        Coroutine\run(
            function () {
                go(
                    function () {
                        $kernel = static::bootKernel();
                    }
                );
            }
        );
    }
}

Results with:

===================================================================
 [FATAL ERROR]: all coroutines (count: 1) are asleep - deadlock!
===================================================================

 [Coroutine-2]
--------------------------------------------------------------------
#0  flock() called at [/home/project/Projects/V2/telephony-libs/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:466]
#1  Symfony\Component\HttpKernel\Kernel->initializeContainer() called at [/home/project/Projects/V2/telephony-libs/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:780]
#2  Symfony\Component\HttpKernel\Kernel->preBoot() called at [/home/project/Projects/V2/telephony-libs/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:121]
#3  Symfony\Component\HttpKernel\Kernel->boot() called at [/home/project/Projects/V2/telephony-libs/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:80]
#4  Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::bootKernel() called at [/home/project/Projects/V2/telephony-libs/tests/Reproduce/InsideCoroKernelBootTest.php:18]

php 7.4.16 + swoole 4.6.6 + symfony http-kernel v5.2.9