SkolemIriConverter isn't reset between requests in worker mode (missing kernel.reset tag)
维护者通常 1 天内回复
评估
调研方向
从 Symfony bundle 配置中 api_platform.symfony.iri_converter.skolem 的服务定义开始,并查看 SkolemIriConverter。它实现了 ResetInterface 并持有 objectHashMap 属性。检查该服务是否缺少 kernel.reset 标签,然后确认重置调用是否通过 services_resetter 连接。当复现案例中的 skolem 映射在每次重置后都为空时,即完成。
由索引模型根据 Issue 内容生成。
描述
API Platform version(s) affected: 5.0.2 (also 4.4 and main)
Description
I've been upgrading one of our projects to API Platform 5 (Symfony 8.1, FrankenPHP in worker mode). One endpoint returns embedded objects that aren't resources themselves, so they get /.well-known/genid/... IRIs. With that endpoint, a single worker's memory kept growing until it hit our 128M memory_limit. It only took about five requests.
it seems the skolem IRI converter keeps an object → IRI map, and it is never cleared between requests.
I think the cause is that SkolemIriConverter already implements ResetInterface, but its service (api_platform.symfony.iri_converter.skolem) isn't tagged kernel.reset, so services_resetter never calls it. As far as I can see, it's the same in 4.4, 5.0 and main.
How to reproduce
- Create a resource that returns an embedded object which isn't itself a resource, so it gets a genid IRI. For example:
#[ApiResource(operations: [new Get(provider: [self::class, 'provide'])])]
final class Report
{
public string $id = '1';
/** @var Line[] */
public array $lines = [];
public static function provide(): self
{
$r = new self();
foreach (range(1, 500) as $i) {
$r->lines[] = new Line(str_repeat('x', 1000));
}
return $r;
}
}
final class Line
{
public function __construct(public string $text) {}
}
- Boot the kernel once and send several requests through it. Run the services resetter between them, as a FrankenPHP worker would:
$kernel = new Kernel('prod', false);
$kernel->boot();
$skolem = $kernel->getContainer()->get('api_platform.symfony.iri_converter.skolem');
$map = (new \ReflectionProperty($skolem, 'objectHashMap'));
for ($i = 1; $i <= 5; $i++) {
$response = $kernel->handle(Request::create('/reports/1', 'GET', server: ['HTTP_ACCEPT' => 'application/ld+json']));
$kernel->terminate($request ?? Request::create('/'), $response);
$kernel->getContainer()->get('services_resetter')->reset();
printf("request %d: %d skolem entries, %.1f MB\n", $i, count($map->getValue($skolem)), memory_get_usage() / 1048576);
}
- Expected: the skolem map is empty, or at least stays flat, after each reset. What happens: it grows by the number of embedded objects on every request (500, 1000, 1500, …), and memory grows with it. In our app it reached the 128M limit within about five requests.
- Add the kernel.reset tag (see the workaround below) and run it again. The map is cleared after each request, and memory stays flat.
Possible Solution
Add the tag where the service is registered:
->tag('kernel.reset', ['method' => 'reset'])
Additional Context
Workaround for now
override the service definition ourselves for api_platform.symfony.iri_converter.skolem to add the tag
With that in place, memory stays flat across requests.
I'll raise a short PR
- 主要语言
- PHP
- 星标
- 2.6k
- 派生
- 989
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 87
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
api-platform/core 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 54/100
api-platform/core#8664 · 1 条评论 ·
维护者通常 1 天内回复
-
[Metadata] Incorrect api schema for path variable可能已有人在做 @bram123 于 2 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
api-platform/core#8646 · 1 条评论 ·
维护者通常 1 天内回复
-
DenormalizationViolationFactory crash when GroupSequence is used可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 64/100
api-platform/core#8639 ·
维护者通常 1 天内回复
-
HTTP cache purgers error handling and performance issues可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 3-5 天 新手友好度 38/100
api-platform/core#8591 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
api-platform/core#8535 · 1 条评论 ·
维护者通常 1 天内回复
查看 api-platform/core 的全部 Issue
相似的 Issue
-
sync-en
难度 1/5 1-3 小时 新手友好度 68/100
维护者通常 4 天内回复
-
Перевод устарел
难度 2/5 半天 新手友好度 62/100
-
feature request
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
home php
难度 2/5 1-3 小时 新手友好度 62/100
vincent-peugnet/wcms#670 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
freescout-help-desk/freescout#5731 · 1 条评论 ·
维护者通常 1 天内回复