Skip to content

Commit 07eb8fb

Browse files
committed
Prevent switching fibers in tick function
1 parent 928624e commit 07eb8fb

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Zend/tests/fibers/ticks.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Prevent switchcing fibers in tick function
3+
--FILE--
4+
<?php
5+
6+
declare(ticks=1);
7+
8+
register_tick_function(function (): void {
9+
if (Fiber::getCurrent() !== null) {
10+
Fiber::suspend();
11+
}
12+
});
13+
14+
$fiber = new Fiber(function (): void {
15+
echo "1\n";
16+
echo "2\n";
17+
echo "3\n";
18+
});
19+
20+
$fiber->start();
21+
22+
?>
23+
--EXPECTF--
24+
1
25+
26+
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sticks.php:%d
27+
Stack trace:
28+
#0 %sticks.php(%d): Fiber::suspend()
29+
#1 %sticks.php(%d): {closure}()
30+
#2 [internal function]: {closure}()
31+
#3 %sticks.php(%d): Fiber->start()
32+
#4 {main}
33+
thrown in %sticks.php on line %d

Zend/zend_vm_def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7752,7 +7752,9 @@ ZEND_VM_HANDLER(105, ZEND_TICKS, ANY, ANY, NUM)
77527752
EG(ticks_count) = 0;
77537753
if (zend_ticks_function) {
77547754
SAVE_OPLINE();
7755+
zend_fiber_switch_block();
77557756
zend_ticks_function(opline->extended_value);
7757+
zend_fiber_switch_unblock();
77567758
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
77577759
}
77587760
}

Zend/zend_vm_execute.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)