swoole-src icon indicating copy to clipboard operation
swoole-src copied to clipboard

Calling macro `swoole_fatal_error` will immediately terminate the process without executing `php_request_shutdown` in Swoole 5.1.x

Open Appla opened this issue 1 year ago • 2 comments

With the following codes, php_request_shutdown will be called in PHP 7.4 + Swoole 4.8.x but not in PHP 8.3 + Swoole 5.1.x. Is this expected behavior?

\register_shutdown_function(static function () {
    echo "register_shutdown_function called\n";
});
echo "before\n";
\Swoole\Coroutine::create(static function () {
    (new \Swoole\Process(static fn() => file_get_contents('https://www.google.com')))->start();
});
echo "after\n";
\Swoole\Event::wait();

Outputs:

  • PHP 8.3 + 5.1.3
before

Fatal error: Uncaught Swoole\Error: must be forked outside the coroutine in /path/to/test.php:8
Stack trace:
#0 /path/to/test.php(8): Swoole\Process->start()
#1 [internal function]: {closure}()
#2 {main}
  thrown in  /path/to/test.php on line 8
  • PHP 7.4 + Swoole 4.8.13
before
PHP Fatal error:  Uncaught Swoole\Error: must be forked outside the coroutine in /path/to/test.php:8
Stack trace:
#0 /path/to/test.php(8): Swoole\Process->start()
#1 {main}
  thrown in /path/to/test.php on line 8
register_shutdown_function called

Appla avatar Jun 27 '24 09:06 Appla

In coroutines, fork or Swoole\Process cannot be used, otherwise the coroutine context will be duplicated.

NathanFreeman avatar Jun 29 '24 03:06 NathanFreeman

In coroutines, fork or Swoole\Process cannot be used, otherwise the coroutine context will be duplicated.

The above example is intended to trigger swoole_fatal_error to demonstrate the issue.

Appla avatar Jun 29 '24 06:06 Appla

The swoole_fatal_error is triggered, which indicates that it is not a runtime error, there is a problem with your code, you must modify the code.

swoole_fatal_error cannot be caught, and the program will exit immediately.

matyhtf avatar Jul 06 '24 06:07 matyhtf