[php-src] Issue #10134: Non-suspended generators in suspended Fiber do not participate in GC
| From: | arnaud-lb | Date: | Tue, 20 Dec 2022 11:24:32 +0000 |
| Subject: | [php-src] Issue #10134: Non-suspended generators in suspended Fiber do not participate in GC | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243199@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10134
Author: arnaud-lb
### Description
Found this while checking if https://github.com/php/php-src/issues/9916
also happened during GC.
The following code:
```php
<?php
class Canary {
public function __construct(
public readonly string $x,
) {
}
public function __destruct() {
var_dump($this->x);
}
}
$gen = (function() {
$canary = new Canary('Generator dtor');
$fiber = yield;
Fiber::suspend();
})();
$fiber = new Fiber(function() use ($gen, &$fiber) {
$canary = new Canary('Fiber dtor');
$gen->send($fiber);
});
$fiber->start();
$gen = null;
$fiber = null;
gc_collect_cycles();
var_dump('Shutdown');
```
Resulted in this output:
```
string(8) "Shutdown"
string(14) "Generator dtor"
string(10) "Fiber dtor"
```
But I expected this output instead:
```
string(14) "Generator dtor"
string(10) "Fiber dtor"
string(8) "Shutdown"
```
### PHP Version
PHP 8.1
### Operating System
_No response_