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

Fix incorrect bailout checkpoint #5196

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
11 changes: 5 additions & 6 deletions ext-src/swoole_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
28 changes: 28 additions & 0 deletions tests/swoole_coroutine/bailout/co_redis_in_shutdown_function.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
swoole_coroutine/bailout: call co redis in shutdown function
--SKIPIF--
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../../include/bootstrap.php';

use Swoole\Event;

Co\run(function () {
$redis = new \redis();
$redis->connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT);
register_shutdown_function(function () use ($redis) {
$redis->get('key');
});
usleep(10000);
});

Event::wait();
?>
--EXPECTF--
Fatal error: Uncaught Swoole\Error: API must be called in the coroutine in %s:%d
Stack trace:
#0 %s(%d): Redis->get('key')
#1 [internal function]: {closure}()
#2 {main}
thrown in %s on line %d
6 changes: 0 additions & 6 deletions tests/swoole_mysql_coro/another_coroutine.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ swoole_mysql_coro: illegal another coroutine
require __DIR__ . '/../include/bootstrap.php';
$process = new Swoole\Process(function () {
Co\run(function () {
register_shutdown_function(function () {
$msg = (error_get_last() ?? [])['message'] ?? '';
Assert::true(str_contains($msg, 'has already been bound to another coroutine'));
echo "DONE\n";
});
function get(Co\Mysql $cli)
{
$cli->query('SELECT SLEEP(1)');
Expand Down Expand Up @@ -54,4 +49,3 @@ Stack trace:
#3 %s(%d): {closure}()
%A
thrown in %s on line %d
DONE
Loading