Non-suspended generators in suspended Fiber do not participate in GC
未关闭
还没有人认领这个 Issue。
Bug
Category: Engine
Category: Fibers
Category: GC
Category: Generators
Status: Verified
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
Found this while checking if https://github.com/php/php-src/issues/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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 PHP 8.1 复现程序,并跟踪 gc_collect_cycles() 期间 Fiber 和 Generator 的生命周期。调查由已暂停的 Fiber 持有的未暂停 Generator 如何参与垃圾回收;完成标准是两个析构函数都在 "Shutdown" 输出之前运行。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100