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

Fatal error: Unable to call Event::wait() in coroutine #5704

Closed
anggrekmerah opened this issue Mar 7, 2025 · 1 comment
Closed

Fatal error: Unable to call Event::wait() in coroutine #5704

anggrekmerah opened this issue Mar 7, 2025 · 1 comment
Labels

Comments

@anggrekmerah
Copy link

Please help for this error, i use docker image FROM phpswoole/swoole:6.0-php8.4

Running Code

use Swoole\Coroutine;
use Swoole\Http\Request;
use Swoole\Http\Response;

Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);

$http = new Swoole\Http\Server("0.0.0.0", 9501);

$http->on("request", function (Request $request, Response $response) {
    Coroutine\run(function () use ($response) {
        $response->header("Content-Type", "text/plain");
        $response->end("Hello, Swoole!");
    });
});

$http->start();

I got fatal error

Important

Fatal error: Swoole\Coroutine\Scheduler::start(): Unable to call Event::wait() in coroutine in @swoole/library/core/Coroutine/functions.php on line 24
ERROR php_swoole_server_rshutdown() (ERRNO 503): Fatal error: Swoole\Coroutine\Scheduler::start(): Unable to call Event::wait() in coroutine in @swoole/library/core/Coroutine/functions.php on line 24

uname -a
Linux 3f54fbff9b0e 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux

php -v
PHP 8.4.4 (cli) (built: Feb 14 2025 02:30:31) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.4, Copyright (c) Zend Technologies

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/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='Debian 12.2.0-14' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --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 --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-12-bTRWOB/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --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 12.2.0 (Debian 12.2.0-14)

php --ri swoole
swoole

Swoole => enabled
Author => Swoole Team team@swoole.com
Version => 6.0.1
Built => Feb 17 2025 06:18:16
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.15 3 Sep 2024
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
curl-version => 7.88.1
zlib => 1.2.13
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
coroutine_pgsql => enabled
coroutine_sqlite => enabled

Directive => Local Value => Master Value
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
random
readline
redis
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
swoole
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

@matyhtf
Copy link
Member

matyhtf commented Mar 7, 2025

When event callbacks of Swoole\Server are executed, coroutines are automatically created, so there's no need to manually create coroutines in PHP code. Additionally, Coroutine\run doesn't create coroutines; instead, it creates a runtime container for coroutines, which only needs to be initialized once during the program's lifecycle.

The correct approach is to omit Coroutine\run and directly implement the specific logic. Alternatively, you can disable the server's enable_coroutine option and manually create coroutines.

use Swoole\Coroutine;
use Swoole\Http\Request;
use Swoole\Http\Response;

Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);

$http = new Swoole\Http\Server("0.0.0.0", 9501);

$http->on("request", function (Request $request, Response $response) {
        $response->header("Content-Type", "text/plain");
        sleep(1);
        $response->end("Hello, Swoole!");
});

$http->start();

Or

use Swoole\Coroutine;
use Swoole\Http\Request;
use Swoole\Http\Response;

Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);

$http = new Swoole\Http\Server("0.0.0.0", 9501);
$http->set(['enable_coroutine' => false]);

$http->on("request", function (Request $request, Response $response) {
    Coroutine\go(function () use ($response) {
        $response->header("Content-Type", "text/plain");
        sleep(1);
        $response->end("Hello, Swoole!");
    });
});

$http->start();

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

No branches or pull requests

2 participants