openswoole / ext-openswoole

Programmatic server for PHP with async IO, coroutines and fibers
https://openswoole.com
Apache License 2.0
808 stars 51 forks source link

Coroutine inside a task makes worker crash #339

Closed vianeostech closed 1 year ago

vianeostech commented 1 year ago
  1. What did you do? If possible, provide a simple script for reproducing the error.
    
    I created this simple script to be able to create a coroutine inside a server task.
    *******
    <?php
    $server = new OpenSwoole\Server("127.0.0.1", 9501, OpenSwoole\Server::SIMPLE_MODE);
    $server->set( [ 'worker_num' => 1,
                     'task_worker_num' => 1,
                'task_enable_coroutine' => true ]);

$server->on('Receive', function (OpenSwoole\Server $server, $fd, $reactorId, $data) {

$server->task("taskcallback", -1, function (OpenSwoole\Server $server, $task_id, $data) { echo 'starting task' . PHP_EOL; });

});

$server->on("Task", function(OpenSwoole\Server $server, OpenSwoole\Server\Task $task ) { var_dump($task); Co::run(function() { Co::sleep(1); // } }); });


When I telnet localhost 9501 the program crashes.

2. What did you expect to see?

I expect the coroutine inside the task to make a sleep and exit

3. What did you see instead?

program crashes with the following error :

[2023-11-08 19:08:27 $590.0] WARNING Server::check_worker_exit_status(): worker(pid=591, id=1) abnormal exit, status=0, signal=11 A bug occurred in OpenSwoole-v22.0.0, please report it. Please submit bug report at:

https://github.com/openswoole/swoole-src/issues

OS: Linux 4.4.0-19041-Microsoft #3570-Microsoft Fri Sep 29 17:00:00 PST 2023 x86_64 GCC_VERSION: 11.3.0 OPENSSL_VERSION: OpenSSL 3.0.2 15 Mar 2022 PHP_VERSION : 8.1.13

4. What version of OpenSwoole are you using (show your `php --ri openswoole`)?

openswoole

Open Swoole => enabled Author => Open Swoole Group hello@openswoole.com Version => 22.0.0 Built => Dec 22 2022 13:01:47 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 3.0.2 15 Mar 2022 dtls => enabled http2 => enabled mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled postgresql => enabled

Directive => Local Value => Master Value openswoole.enable_coroutine => On => On openswoole.enable_preemptive_scheduler => Off => Off openswoole.display_errors => On => On openswoole.unixsock_buffer_size => 8388608 => 8388608

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

Note I am running openswoole under WSL1 Ubuntu 22.04

uname -a : Linux PC-XXXXX 4.4.0-19041-Microsoft #3570-Microsoft Fri Sep 29 17:00:00 PST 2023 x86_64 x86_64 x86_64 GNU/Linux

php -v :
PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies

gcc -v : Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --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-bootstrap --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 --enable-cet --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-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

You can also try the following OpenSwoole support channels:

doubaokun commented 1 year ago

Should no use co::run in the callback, but you can try to use go.

vianeostech commented 1 year ago

At least the worker does not crash anymore and the content of go is running properly.

Thank you :-)