Skip to content

Commit

Permalink
Catch C++ exception when thread creation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jun 7, 2024
1 parent 97d91e3 commit d62d292
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ext-src/swoole_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ bool php_swoole_thread_unserialize(zend_string *data, zval *zv) {
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
if (!unserialized) {
swoole_warning("unserialize() failed, Error at offset " ZEND_LONG_FMT " of %zd bytes",
(zend_long)((char *) p - ZSTR_VAL(data)),
(zend_long) ((char *) p - ZSTR_VAL(data)),
l);
} else {
if (ZVAL_IS_ARRAY(zv)) {
Expand Down Expand Up @@ -371,7 +371,12 @@ static void php_swoole_thread_create(INTERNAL_FUNCTION_PARAMETERS, zval *zobject
return;
}

to->thread = new std::thread([file, argv]() { php_swoole_thread_start(file, argv); });
try {
to->thread = new std::thread([file, argv]() { php_swoole_thread_start(file, argv); });
} catch (const std::exception &e) {
zend_throw_exception(swoole_exception_ce, e.what(), SW_ERROR_SYSTEM_CALL_FAIL);
return;
}
zend_update_property_long(
swoole_thread_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("id"), (zend_long) to->thread->native_handle());
}
Expand Down

0 comments on commit d62d292

Please sign in to comment.