Skip to content

Commit 419256b

Browse files
committed
Fix _ZendTestFiber failed assertion when started twice
Fixes GH-16496
1 parent 5c21042 commit 419256b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

ext/zend_test/fiber.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,14 @@ static ZEND_METHOD(_ZendTestFiber, start)
247247
Z_PARAM_VARIADIC_WITH_NAMED(params, param_count, named_params);
248248
ZEND_PARSE_PARAMETERS_END();
249249

250-
ZEND_ASSERT(fiber->context.status == ZEND_FIBER_STATUS_INIT);
250+
if (fiber->context.status != ZEND_FIBER_STATUS_INIT) {
251+
zend_string *fiber_error_name = ZSTR_INIT_LITERAL("fibererror", false);
252+
zend_class_entry *fiber_error_ce = zend_lookup_class_ex(fiber_error_name, fiber_error_name, 0);
253+
ZEND_ASSERT(fiber_error_ce);
254+
zend_throw_error(fiber_error_ce, "Cannot start a fiber that has already been started");
255+
zend_string_release_ex(fiber_error_name, false);
256+
RETURN_THROWS();
257+
}
251258

252259
if (fiber->previous != NULL) {
253260
zend_throw_error(NULL, "Cannot start a fiber that is the target of another fiber");

ext/zend_test/tests/gh16496.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-16496: _ZendTestFiber failed assertion when started twice
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
$test = new _ZendTestFiber(function () {});
9+
$test->start();
10+
11+
try {
12+
$test->start();
13+
} catch(FiberError $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
17+
?>
18+
--EXPECT--
19+
Cannot start a fiber that has already been started

0 commit comments

Comments
 (0)