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

dispatch_func always results in recursion in 5.1.1 / 8.3 #5209

Closed
kenashkov opened this issue Dec 3, 2023 · 4 comments · Fixed by #5223
Closed

dispatch_func always results in recursion in 5.1.1 / 8.3 #5209

kenashkov opened this issue Dec 3, 2023 · 4 comments · Fixed by #5223

Comments

@kenashkov
Copy link

kenashkov commented Dec 3, 2023

Please answer these questions before submitting your issue.

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

declare(strict_types=1);

use Swoole\Http\Server;

error_reporting(E_ALL);

$options = [
    'worker_num' => 4,
    'dispatch_func' => static fn () => 0,
];
$server = new Server('127.0.0.1', 4455, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
$server->set($options);
$server->on("Request", function(\Swoole\Http\Request $request, \Swoole\Http\Response $response) use ($server)
{
    print 'response w ' . $server->worker_id . PHP_EOL;
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});
$server->start();
  1. What did you expect to see?

The request to be processed as expected by worker 0 without errors

  1. What did you see instead?
Fatal error: Uncaught Error: Maximum call stack size of 8339456 bytes reached. Infinite recursion? in /var/www/test1.php:11
Stack trace:
#0 [internal function]: {closure}(Object(Swoole\Http\Server), 1, 4)
#1 /var/www/test1.php(21): Swoole\Server->start()
#2 {main}
  thrown in /var/www/test1.php on line 11

The request was still processed (by worker 0 as expected) but the above error is shown. It works with Swoole 5.1.0 / php 8.2 (phpswoole/swoole:5.1.0-php8.2) as expected.

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

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

To run the example I use "phpswoole/swoole:5.1.1-php8.3"

Linux swoole-host 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 GNU/Linux
PHP 8.3.0 (cli) (built: Nov 27 2023 21:24:30) (NTS)

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 5.1.1
Built => Nov 28 2023 01:15:32
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.11 19 Sep 2023
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
zlib => 1.2.13
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled
coroutine_pgsql => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
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


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)
@kenashkov kenashkov changed the title dispatch_func always results in recursion dispatch_func always results in recursion in 5.1.1 / 8.3 Dec 3, 2023
@smathersPersonal
Copy link

smathersPersonal commented Mar 3, 2024

Hi there, unfortunately I'm still experiencing this error.

PHP Fatal error:  Uncaught Error: Maximum call stack size of 8339456 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?

Example:
...
$server = new Swoole\HTTP\Server('[::]', 9009, SWOOLE_PROCESS);
$sTables = new SwooleTables();
$sTables->worker = ProcessHelper::setupWorkerTable();
$cpus = swoole_cpu_num();
$server->set([
  'log_level' => 4,
  'reactor_num' => $cpus * 2,
  'worker_num' => $cpus * 8,
  'enable_coroutine' => true,
  'hook_flags' => SWOOLE_HOOK_TCP | SWOOLE_HOOK_NATIVE_CURL | SWOOLE_HOOK_SLEEP | SWOOLE_HOOK_BLOCKING_FUNCTION,
  'dispatch_func' => static fn () => 0,
  'package_max_length' => 30 * 1024 * 1024 // 30MB
]);
...

I've tried code from latest master and also 5.1.2
My setup:

Linux d-ivr01 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 19:20:45 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

PHP 8.3.2 (cli) (built: Feb 29 2024 20:34:57) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/11/lto-wrapper
Target: aarch64-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,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=aarch64-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-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-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)

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 5.1.2
Built => Mar  3 2024 02:35:51
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
json => enabled
curl-native => 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_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


@ValiDrv
Copy link

ValiDrv commented May 13, 2024

I can confirm the same with PHP php:8.3.7-cli and swoole v5.1.2, but usually happens if it gets a request before everything is started, like ping health checks.

@NathanFreeman
Copy link
Member

@kenashkov @ValiDrv @smathersPersonal
We have released Swoole v5.1.3. You can try Swoole v5.1.3 to see if this issue still exists.

@smathersPersonal
Copy link

Just tested, so far no errors!! Thanks !
php-8.3.8, Swoole v5.1.3

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

Successfully merging a pull request may close this issue.

5 participants