Bug #79657 [Ver->Csd]: "yield from" hangs when invalid value encountered
| From: | nikic@php.net | Date: | Mon, 08 Jun 2020 09:32:37 +0000 |
| Subject: | Bug #79657 [Ver->Csd]: "yield from" hangs when invalid value encountered | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227353@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79657&edit=1
ID: 79657
Updated by: nikic@php.net
Reported by: max dot tun at pm dot me
Summary: "yield from" hangs when invalid value encountered
-Status: Verified
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Alpine Linux
PHP Version: 7.4.6
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=df2db7fceaff4f46909f1aa8b31f0a9010631fc9
Log: Fixed bug #79657
Previous Comments:
------------------------------------------------------------------------
[2020-05-31 17:09:28] max dot tun at pm dot me
Description:
------------
Starting from PHP 7.4.6 (I've managed to reproduce on 7.4.7RC1 as well) "yield from"
hangs when I try to unwrap generator into function arguments and an invalid value is encountered or
an exception is thrown.
In the example provided this won't happen if the "get" function doesn't have
arguments.
This also doesn't happen if I unwrap the generator into an array.
Also, works as expected if an error occurs on first iteration.
The script hangs on line #15 and CPU usage and memory consumption increases significantly, looks
like there's an infinite loop.
Test script:
---------------
<?php
function throwException(): iterable
{
throw new Exception();
}
function loop(): iterable
{
$callbacks = [
function () {
yield 'first';
},
function () {
yield from throwException();
}
];
foreach ($callbacks as $callback) {
yield from $callback();
}
}
function get(string $first, int $second): array
{
return [];
}
get(...loop());
Expected result:
----------------
Either this if I throw an exception:
Fatal error: Uncaught Exception in test.php:5
Stack trace:
#0 test.php(15): throwException()
#1 test.php(20): {closure}()
#2 test.php(29): loop()
#3 {main}
thrown in test.php on line 5
Or the following if an invalid value is being used to yield from:
Fatal error: Uncaught Error: Can use "yield from" only with arrays and Traversables in
test.php:15
Stack trace:
#0 test.php(20): {closure}()
#1 test.php(29): loop()
#2 {main}
thrown in test.php on line 15
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79657&edit=1