Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Zend/tests/fibers/gh24265-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-24265 (exit() in a finally block of a destroyed fiber is discarded)
--CREDITS--
iluuu1994
--FILE--
<?php

$fiber = new Fiber(function () {
try {
Fiber::suspend();
} finally {
exit(1);
}
});

$fiber->start();
echo "Before destroy", PHP_EOL;
unset($fiber);

echo "Not reached", PHP_EOL;

?>
--EXPECT--
Before destroy
30 changes: 30 additions & 0 deletions Zend/tests/fibers/gh24265-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
GH-24265 (exit() in a destroyed fiber is discarded while an exception is pending)
--FILE--
<?php

function test() {
$fiber = new Fiber(function () {
try {
Fiber::suspend();
} finally {
exit(1);
}
});

$fiber->start();
echo "Before destroy", PHP_EOL;
throw new Exception("pending");
}

try {
test();
} catch (Exception $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

echo "Not reached", PHP_EOL;

?>
--EXPECT--
Before destroy
4 changes: 1 addition & 3 deletions Zend/zend_fibers.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,7 @@ static ZEND_STACK_ALIGNED void zend_fiber_execute(zend_fiber_transfer *transfer)
zend_fiber_release_callable(fiber);

if (EG(exception)) {
if (!(fiber->flags & ZEND_FIBER_FLAG_DESTROYED)
|| !(zend_is_graceful_exit(EG(exception)) || zend_is_unwind_exit(EG(exception)))
) {
if (!(fiber->flags & ZEND_FIBER_FLAG_DESTROYED) || !zend_is_graceful_exit(EG(exception))) {
fiber->flags |= ZEND_FIBER_FLAG_THREW;
transfer->flags = ZEND_FIBER_TRANSFER_FLAG_ERROR;

Expand Down
Loading