Skip to content

Commit 62fd459

Browse files
authored
Exit the process directly when a fatal error occurs (swoole#4053)
* Exit the process directly when a fatal error occurs * use zend_try * fix tests * fix tests [2]
1 parent b41cdea commit 62fd459

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

ext-src/php_swoole.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ SW_API bool php_swoole_is_enable_coroutine() {
397397

398398
static void fatal_error(int code, const char *format, ...) {
399399
va_list args;
400-
zend_object *exception;
401-
if (sw_reactor()) {
402-
sw_reactor()->bailout = true;
403-
}
404400
va_start(args, format);
405-
exception = zend_throw_exception(swoole_error_ce, swoole::std_string::vformat(format, args).c_str(), code);
401+
zend_object *exception = zend_throw_exception(swoole_error_ce, swoole::std_string::vformat(format, args).c_str(), code);
406402
va_end(args);
407-
zend_exception_error(exception, E_ERROR);
408-
exit(255);
403+
404+
zend_try {
405+
zend_exception_error(exception, E_ERROR);
406+
} zend_catch {
407+
exit(255);
408+
} zend_end_try();
409409
}
410410

411411
/* {{{ PHP_MINIT_FUNCTION

ext-src/php_swoole.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ extern zend_class_entry *swoole_websocket_frame_ce;
174174
extern zend_class_entry *swoole_server_port_ce;
175175
extern zend_class_entry *swoole_exception_ce;
176176
extern zend_object_handlers swoole_exception_handlers;
177+
extern zend_class_entry *swoole_error_ce;;
177178

178179
PHP_MINIT_FUNCTION(swoole);
179180
PHP_MSHUTDOWN_FUNCTION(swoole);

ext-src/swoole_coroutine.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ void PHPCoroutine::activate() {
325325
sw_reactor()->running = false;
326326
sw_reactor()->bailout = true;
327327
}
328+
#ifdef SW_EXIT_WHEN_OCCURS_FATAL_ERROR
329+
zend_try {
330+
orig_error_function(type, error_filename, error_lineno, ZEND_ERROR_CB_LAST_ARG_RELAY);
331+
} zend_catch {
332+
exit(255);
333+
} zend_end_try();
334+
#endif
328335
}
329336
if (sw_likely(orig_error_function)) {
330337
orig_error_function(type, error_filename, error_lineno, ZEND_ERROR_CB_LAST_ARG_RELAY);

tests/swoole_mysql_coro/another_coroutine.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,3 @@ Stack trace:
6363
#3 %s(%d): {closure}()
6464
#4 {main}
6565
thrown in %s on line %d
66-
DONE

0 commit comments

Comments
 (0)