Skip to content

Commit

Permalink
Fix incorrect bailout checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Nov 20, 2023
1 parent 067fbc3 commit d0622c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
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
26 changes: 26 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,26 @@
--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) {
try {
$redis->get('key');
}catch (Exception $e) {
var_dump($e);
}
});
usleep(10000);
});

Event::wait();
?>
--EXPECTF--

0 comments on commit d0622c5

Please sign in to comment.