Skip to content

Commit

Permalink
Exit the process directly when a fatal error occurs (#4053)
Browse files Browse the repository at this point in the history
* Exit the process directly when a fatal error occurs

* use zend_try

* fix tests

* fix tests [2]
  • Loading branch information
matyhtf authored Feb 9, 2021
1 parent b41cdea commit 62fd459
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
14 changes: 7 additions & 7 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,15 @@ SW_API bool php_swoole_is_enable_coroutine() {

static void fatal_error(int code, const char *format, ...) {
va_list args;
zend_object *exception;
if (sw_reactor()) {
sw_reactor()->bailout = true;
}
va_start(args, format);
exception = zend_throw_exception(swoole_error_ce, swoole::std_string::vformat(format, args).c_str(), code);
zend_object *exception = zend_throw_exception(swoole_error_ce, swoole::std_string::vformat(format, args).c_str(), code);
va_end(args);
zend_exception_error(exception, E_ERROR);
exit(255);

zend_try {
zend_exception_error(exception, E_ERROR);
} zend_catch {
exit(255);
} zend_end_try();
}

/* {{{ PHP_MINIT_FUNCTION
Expand Down
1 change: 1 addition & 0 deletions ext-src/php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ extern zend_class_entry *swoole_websocket_frame_ce;
extern zend_class_entry *swoole_server_port_ce;
extern zend_class_entry *swoole_exception_ce;
extern zend_object_handlers swoole_exception_handlers;
extern zend_class_entry *swoole_error_ce;;

PHP_MINIT_FUNCTION(swoole);
PHP_MSHUTDOWN_FUNCTION(swoole);
Expand Down
7 changes: 7 additions & 0 deletions ext-src/swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ void PHPCoroutine::activate() {
sw_reactor()->running = false;
sw_reactor()->bailout = true;
}
#ifdef SW_EXIT_WHEN_OCCURS_FATAL_ERROR
zend_try {
orig_error_function(type, error_filename, error_lineno, ZEND_ERROR_CB_LAST_ARG_RELAY);
} zend_catch {
exit(255);
} zend_end_try();
#endif
}
if (sw_likely(orig_error_function)) {
orig_error_function(type, error_filename, error_lineno, ZEND_ERROR_CB_LAST_ARG_RELAY);
Expand Down
1 change: 0 additions & 1 deletion tests/swoole_mysql_coro/another_coroutine.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ Stack trace:
#3 %s(%d): {closure}()
#4 {main}
thrown in %s on line %d
DONE

0 comments on commit 62fd459

Please sign in to comment.