Skip to content

Commit 779fe8e

Browse files
committed
Check current_execute_data instead of flags in fiber destructor
Checking EG(current_exectue_data) throws into the previous fiber instead of triggering a fatal error during shutdown. A fatal error is triggered only if the throwing destroyed fiber was resumed from {main}.
1 parent f9ac667 commit 779fe8e

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Throw in multiple destroyed fibers after shutdown
3+
--FILE--
4+
<?php
5+
6+
$fiber = new Fiber(function (): void {
7+
$fiber1 = new Fiber(function (): void {
8+
try {
9+
Fiber::suspend();
10+
} finally {
11+
throw new Exception('test1');
12+
}
13+
});
14+
15+
$fiber1->start();
16+
17+
$fiber2 = new Fiber(function (): void {
18+
try {
19+
Fiber::suspend();
20+
} finally {
21+
throw new Exception('test2');
22+
}
23+
});
24+
25+
$fiber2->start();
26+
27+
Fiber::suspend();
28+
});
29+
30+
$fiber->start();
31+
32+
echo "done\n";
33+
34+
?>
35+
--EXPECTF--
36+
done
37+
38+
Fatal error: Uncaught Exception: test1 in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php:%d
39+
Stack trace:
40+
#0 [internal function]: {closure}()
41+
#1 {main}
42+
43+
Next Exception: test2 in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php:%d
44+
Stack trace:
45+
#0 [internal function]: {closure}()
46+
#1 {main}
47+
thrown in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php on line %d

Zend/zend_fibers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static void zend_fiber_object_destroy(zend_object *object)
405405

406406
zend_exception_set_previous(EG(exception), exception);
407407

408-
if (EG(flags) & EG_FLAGS_IN_SHUTDOWN) {
408+
if (!EG(current_execute_data)) {
409409
zend_exception_error(EG(exception), E_ERROR);
410410
}
411411
} else {

0 commit comments

Comments
 (0)