-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent fiber switching in tick function and signal handlers (#9028)
- Loading branch information
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
Prevent switching fibers when async signals are enabled | ||
--EXTENSIONS-- | ||
pcntl | ||
posix | ||
--FILE-- | ||
<?php | ||
|
||
pcntl_async_signals(true); | ||
|
||
pcntl_signal(SIGUSR1, function (): void { | ||
if (Fiber::getCurrent() !== null) { | ||
Fiber::suspend(); | ||
} | ||
}); | ||
|
||
$fiber = new Fiber(function (): void { | ||
echo "Fiber start\n"; | ||
posix_kill(posix_getpid(), SIGUSR1); | ||
time_nanosleep(1); | ||
echo "Fiber end\n"; | ||
}); | ||
|
||
$fiber->start(); | ||
|
||
?> | ||
--EXPECTF-- | ||
Fiber start | ||
|
||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %ssignal-async.php:%d | ||
Stack trace: | ||
#0 %ssignal-async.php(%d): Fiber::suspend() | ||
#1 %ssignal-async.php(%d): {closure}(%d, Array) | ||
#2 [internal function]: {closure}() | ||
#3 %ssignal-async.php(%d): Fiber->start() | ||
#4 {main} | ||
thrown in %ssignal-async.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
Prevent switching fibers when dispatching pending signals | ||
--EXTENSIONS-- | ||
pcntl | ||
posix | ||
--FILE-- | ||
<?php | ||
|
||
pcntl_signal(SIGUSR1, function (): void { | ||
if (Fiber::getCurrent() !== null) { | ||
Fiber::suspend(); | ||
} | ||
}); | ||
|
||
$fiber = new Fiber(function (): void { | ||
echo "Fiber start\n"; | ||
|
||
posix_kill(posix_getpid(), SIGUSR1); | ||
|
||
try { | ||
pcntl_signal_dispatch(); | ||
} catch (FiberError $e) { | ||
Fiber::suspend($e); | ||
} | ||
|
||
echo "Fiber end\n"; | ||
}); | ||
|
||
$e = $fiber->start(); | ||
|
||
echo $e, "\n"; | ||
|
||
$fiber->resume(); | ||
|
||
?> | ||
--EXPECTF-- | ||
Fiber start | ||
FiberError: Cannot switch fibers in current execution context in %ssignal-dispatch.php:%d | ||
Stack trace: | ||
#0 %ssignal-dispatch.php(%d): Fiber::suspend() | ||
#1 [internal function]: {closure}(%d, Array) | ||
#2 %ssignal-dispatch.php(%d): pcntl_signal_dispatch() | ||
#3 [internal function]: {closure}() | ||
#4 %ssignal-dispatch.php(%d): Fiber->start() | ||
#5 {main} | ||
Fiber end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
Prevent switching fibers in tick function | ||
--FILE-- | ||
<?php | ||
|
||
declare(ticks=1); | ||
|
||
register_tick_function(function (): void { | ||
if (Fiber::getCurrent() !== null) { | ||
Fiber::suspend(); | ||
} | ||
}); | ||
|
||
$fiber = new Fiber(function (): void { | ||
echo "1\n"; | ||
echo "2\n"; | ||
echo "3\n"; | ||
}); | ||
|
||
$fiber->start(); | ||
|
||
?> | ||
--EXPECTF-- | ||
1 | ||
|
||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sticks.php:%d | ||
Stack trace: | ||
#0 %sticks.php(%d): Fiber::suspend() | ||
#1 %sticks.php(%d): {closure}() | ||
#2 [internal function]: {closure}() | ||
#3 %sticks.php(%d): Fiber->start() | ||
#4 {main} | ||
thrown in %sticks.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters