Skip to content

Commit 1543d20

Browse files
committed
Allow fiber switching during shutdown
1 parent b352261 commit 1543d20

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Fibers in destructors 008: Fibers in shutdown sequence
3+
--FILE--
4+
<?php
5+
6+
register_shutdown_function(function () {
7+
printf("Shutdown\n");
8+
});
9+
10+
class C {
11+
public static $instance;
12+
public function __destruct() {
13+
$f = new Fiber(function () {
14+
printf("Started\n");
15+
Fiber::suspend();
16+
printf("Resumed\n");
17+
Fiber::suspend();
18+
});
19+
$f->start();
20+
$f->resume();
21+
// Can not suspend main fiber
22+
Fiber::suspend();
23+
}
24+
}
25+
26+
C::$instance = new C();
27+
28+
?>
29+
--EXPECTF--
30+
Shutdown
31+
Started
32+
Resumed
33+
34+
Fatal error: Uncaught FiberError: Cannot suspend outside of a fiber in %s:%d
35+
Stack trace:
36+
#0 %s(%d): Fiber::suspend()
37+
#1 [internal function]: C->__destruct()
38+
#2 {main}
39+
thrown in %s on line %d

Zend/zend_objects_API.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_call_destructors(zend_objects_sto
4444
{
4545
EG(flags) |= EG_FLAGS_OBJECT_STORE_NO_REUSE;
4646
if (objects->top > 1) {
47-
zend_fiber_switch_block();
48-
4947
uint32_t i;
5048
for (i = 1; i < objects->top; i++) {
5149
zend_object *obj = objects->object_buckets[i];
@@ -62,8 +60,6 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_call_destructors(zend_objects_sto
6260
}
6361
}
6462
}
65-
66-
zend_fiber_switch_unblock();
6763
}
6864
}
6965

0 commit comments

Comments
 (0)