Skip to content

Commit 8681cd3

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 b66d4db commit 8681cd3

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/fiber.c

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

241241
zend_exception_set_previous(EG(exception), exception);
242242

243-
if (EG(flags) & EG_FLAGS_IN_SHUTDOWN) {
243+
if (!EG(current_execute_data)) {
244244
zend_exception_error(EG(exception), E_ERROR);
245245
}
246246
} else {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--TEST--
2+
Throw in multiple destroyed fibers after shutdown
3+
--EXTENSIONS--
4+
fiber
5+
--FILE--
6+
<?php
7+
8+
$fiber = new Fiber(function (): void {
9+
$fiber1 = new Fiber(function (): void {
10+
try {
11+
Fiber::suspend();
12+
} finally {
13+
throw new Exception('test1');
14+
}
15+
});
16+
17+
$fiber1->start();
18+
19+
$fiber2 = new Fiber(function (): void {
20+
try {
21+
Fiber::suspend();
22+
} finally {
23+
throw new Exception('test2');
24+
}
25+
});
26+
27+
$fiber2->start();
28+
29+
Fiber::suspend();
30+
});
31+
32+
$fiber->start();
33+
34+
echo "done\n";
35+
36+
?>
37+
--EXPECTF--
38+
done
39+
40+
Fatal error: Uncaught FiberExit: Fiber destroyed in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php:%d
41+
Stack trace:
42+
#0 %sthrow-in-multiple-destroyed-fibers-after-shutdown.php(%d): Fiber::suspend()
43+
#1 [internal function]: {closure}()
44+
#2 {main}
45+
46+
Next FiberExit: Fiber destroyed in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php:%d
47+
Stack trace:
48+
#0 %sthrow-in-multiple-destroyed-fibers-after-shutdown.php(%d): Fiber::suspend()
49+
#1 [internal function]: {closure}()
50+
#2 {main}
51+
52+
Next Exception: test1 in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php:%d
53+
Stack trace:
54+
#0 [internal function]: {closure}()
55+
#1 {main}
56+
57+
Next FiberExit: Fiber destroyed in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php:%d
58+
Stack trace:
59+
#0 %sthrow-in-multiple-destroyed-fibers-after-shutdown.php(%d): Fiber::suspend()
60+
#1 [internal function]: {closure}()
61+
#2 {main}
62+
63+
Next Exception: test2 in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php:%d
64+
Stack trace:
65+
#0 [internal function]: {closure}()
66+
#1 {main}
67+
thrown in %sthrow-in-multiple-destroyed-fibers-after-shutdown.php on line %d

0 commit comments

Comments
 (0)