php-runtime/runtime

Swoole runtime error on stress test

CViniciusSDias opened this issue · 4 comments

When recieving a big number of requests (via stress test, for example) while having hook_flags set to SWOOLE_HOOK_ALL, the Runtime triggers the following Swoole error:

app-1 | [2024-04-16 22:31:36 $7.0] WARNING Server::check_worker_exit_status(): worker(pid=19, id=3) abnormal exit, status=0, signal=11
app-1 | A bug occurred in Swoole-v5.1.1, please report it.
app-1 | The Swoole developers probably don't know about it,
app-1 | and unless you report it, chances are it won't be fixed.
app-1 | You can read How to report a bug doc before submitting any bug reports:
app-1 | >> https://github.com/swoole/swoole-src/blob/master/.github/ISSUE.md
app-1 | Please do not send bug reports in the mailing list or personal letters.
app-1 | The issue page is also suitable to submit feature requests.
app-1 |
app-1 | OS: Linux 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64
app-1 | GCC_VERSION: 12.2.0
app-1 | PHP_VERSION : 8.3.4
app-1 |

If I try to use the hook_flag in a bare Swoole server, without Symfony runtime, I get no error. Example:

<?php

use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

$server = new Server('0.0.0.0', 8000, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
$server->set([
    'hook_flags' => SWOOLE_HOOK_ALL
]);
$server->on('request', function (Request $request, Response $response) {
    $response->end('Ok');
});

$server->start();

This does not trigger any error on the same stress test.

Steps to reproduce:

  1. Create a Symfony project;
  2. Install Swoole Runtime;
  3. Create a simple controller (just having return $this->json('Ok'); is enough) to /example;
  4. Run the following stress test: docker run --rm -it williamyeh/wrk -c 100 -d 1 -t8 http://host.docker.internal:8000/example;
  5. Check the application logs and see the error.

Simply changing the hook flags to something like SWOOLE_HOOK_ALL & ~SWOOLE_HOOK_FILE & ~SWOOLE_HOOK_STDIO makes the error go away, so I assume it's a problem that happens when logs are added.

I also opened an issue here: swoole/swoole-src#5294

SWOOLE_HOOK_ALL is the parameter for coroutine, I think the runtime/swoole is not ready for coroutine environment.

By the way, symfony framework is not ready now for coroutine. You can imagine there are many requests are handling in one process, logic codes are switch frequently depends on current context, but symfony's DI cant provider the correct service object depends on context, it will bring some dirty variable and break the logic code.

Unless you have a way to ensure the DI work correct on the swtichable context, runtime/swoole will not working well when open coroutine

@ywisax services normallx dont Switch between requests and symfony and the runtime correcty reset services states via reset interface.

As I think swoole works similar like roadrunner or frankenphp worker mode there should for symfony core be no problem. Sure some bundles my forgot to handle this and can fail with swoole but this should not be a problem with symfony bare skeleton. Or do you have an example which service need to be fixed in the symfony core which is not possible to handle multiple requests?

You can remove

$server->set([
    'hook_flags' => SWOOLE_HOOK_ALL
]);

and try again, to confirm if there is related to coroutine.

I stated this in a previous message:

Simply changing the hook flags to something like SWOOLE_HOOK_ALL & ~SWOOLE_HOOK_FILE & ~SWOOLE_HOOK_STDIO makes the error go away, so I assume it's a problem that happens when logs are added.

So the problem seems to be with either SWOOLE_HOOK_FILE or SWOOLE_HOOK_STDIO (or both).