swoole / swoole-src

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

Segmentation fault when using SoapClient #4650

Closed JustBeYou closed 2 years ago

JustBeYou commented 2 years ago
  1. What did you do? If possible, provide a simple script for reproducing the error.

I am trying to use a SoapClient inside Swoole Coroutines. Sample script below, you will need a SOAP server to test it against. If you throw an exception while using the client inside a coroutine, php will crash with SIGSEGV.

\Swoole\Runtime::enableCoroutine(true);

function soap() {
    $baseUrl = 'https://';
    $baseUrl .= HOST . ':' . 443 . '/';
    $location = $baseUrl . 'sdk/vimService';

    $sp = new SoapClient(realpath(WDSL_PATH), [
        'location' => $location,
        'trace' => 1,
        'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
    ]);

    $sp->__setSoapHeaders(new SoapHeader('http://www.w3.org/2001/XMLSchema-instance', 'NS'));

    // You can do any function call here
    $sp->Login(
        array(
            '_this' => $sp,
            'userName' => USER,
            'password' => PASSWORD,
        )
    );
}

Co\run(function () {
    go(function () {
        soap();
    });

    go(function () {
        throw new Exception("bad");
    });
});
  1. What did you expect to see?

A successful RPC and a thrown exception.

  1. What did you see instead?

A segmentation fault.

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

4.10.0 installed using pecl

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux PHP 7.4.3 (cli) (built: Mar 2 2022 15:36:52) ( NTS )

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --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 --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-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/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
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
matyhtf commented 2 years ago

This may be a bug of soap extension. it will generate a recursive infinite loop Try to disable exception capture of soap.

function soap()
{
    $client = new SoapClient(null, array(
        'location' => "http://localhost:8089/server.php",
        'uri' => "http://localhost:8089/server.php",
        'trace' => 1,
        'exceptions' => false,
        ));

    echo $return = $client->__soapCall("helloWorld", array("world"));
}

2022-03-23 17-36-50 的屏幕截图