Skip to content

Non-suspended generators in suspended Fiber do not participate in GC #10134

Open
@arnaud-lb

Description

@arnaud-lb

Description

Found this while checking if #9916 also happened during GC.

The following code:

<?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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions