From d0622c57071ba884b7031d46bad32e147b984898 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 20 Nov 2023 18:51:52 +0800 Subject: [PATCH] Fix incorrect bailout checkpoint --- ext-src/php_swoole.cc | 9 +++---- ext-src/swoole_event.cc | 11 ++++---- .../co_redis_in_shutdown_function.phpt | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 tests/swoole_coroutine/bailout/co_redis_in_shutdown_function.phpt diff --git a/ext-src/php_swoole.cc b/ext-src/php_swoole.cc index ee01acf97b0..262aa35ac02 100644 --- a/ext-src/php_swoole.cc +++ b/ext-src/php_swoole.cc @@ -352,12 +352,9 @@ static void fatal_error(int code, const char *format, ...) { zend_object *exception = zend_throw_exception(swoole_error_ce, swoole::std_string::vformat(format, args).c_str(), code); va_end(args); - if (EG(bailout)) { - zend_bailout(); - } else { - zend_exception_error(exception, E_ERROR); - exit(255); - } + + zend_exception_error(exception, E_ERROR); + exit(255); } static void bug_report_message_init() { diff --git a/ext-src/swoole_event.cc b/ext-src/swoole_event.cc index 92304942fbe..018047a0773 100644 --- a/ext-src/swoole_event.cc +++ b/ext-src/swoole_event.cc @@ -668,14 +668,13 @@ static PHP_FUNCTION(swoole_event_wait) { static PHP_FUNCTION(swoole_event_rshutdown) { /* prevent the program from jumping out of the rshutdown */ zend_try { - if (php_swoole_is_fatal_error() || !sw_reactor()) { - return; - } // when throw Exception, do not show the info - if (!sw_reactor()->bailout) { - php_swoole_fatal_error(E_DEPRECATED, "Event::wait() in shutdown function is deprecated"); + if (!php_swoole_is_fatal_error() && sw_reactor()) { + if (!sw_reactor()->bailout) { + php_swoole_fatal_error(E_DEPRECATED, "Event::wait() in shutdown function is deprecated"); + } + php_swoole_event_wait(); } - php_swoole_event_wait(); } zend_end_try(); } diff --git a/tests/swoole_coroutine/bailout/co_redis_in_shutdown_function.phpt b/tests/swoole_coroutine/bailout/co_redis_in_shutdown_function.phpt new file mode 100644 index 00000000000..9c208761163 --- /dev/null +++ b/tests/swoole_coroutine/bailout/co_redis_in_shutdown_function.phpt @@ -0,0 +1,26 @@ +--TEST-- +swoole_coroutine/bailout: call co redis in shutdown function +--SKIPIF-- + +--FILE-- +connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT); + register_shutdown_function(function () use ($redis) { + try { + $redis->get('key'); + }catch (Exception $e) { + var_dump($e); + } + }); + usleep(10000); +}); + +Event::wait(); +?> +--EXPECTF--