FPM: fpm_request_end() releases the scoreboard writer lock without acquiring it (8.6 regression)

未关闭 适合新手
#26,066 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, php
领域
backend

调研方向

阅读 sapi/fpm/fpm/fpm_request.c 中 fpm_request_end() 附近的代码,并将其中对 scoreboard 的调用与同一文件中的 begin/commit 配对进行比较。检查 sapi/fpm/fpm/fpm_scoreboard.c 中的锁行为;issue 指出了缺失的调用,以及将其安全地放在 fpm_scoreboard_proc_release(proc) 之后的位置。完成标准是:request end 在提交前获取写锁,且 proc == NULL 返回路径保持不变。

由索引模型根据 Issue 内容生成。

描述

Description

In PHP 8.6 the FPM scoreboard write path was split into two halves:

  • fpm_scoreboard_update_begin() acquires scoreboard->writer_active and waits for reader_count == 0.
  • fpm_scoreboard_update_commit() writes the shared counters and then releases writer_active (fpm_unlock(scoreboard->writer_active);, sapi/fpm/fpm/fpm_scoreboard.c:218).

Every writer pairs the two calls — e.g. in sapi/fpm/fpm/fpm_request.c at lines 45/58 and 77/102 — except fpm_request_end(), which calls only commit:

sapi/fpm/fpm/fpm_request.c:205

fpm_scoreboard_update_commit(-1, -1, -1, -1, -1, -1, -1, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);

with no preceding fpm_scoreboard_update_begin().

Because commit ends by releasing writer_active, at the end of every request fpm_request_end():

  1. releases a writer lock it never acquired — if another process legitimately holds writer_active at that moment, this clears it, letting a second writer and readers run concurrently with it; and
  2. updates the shared counters (memory_peak, active_max, ...) without first ensuring reader_count == 0, so a concurrent ?full status reader (fpm_scoreboard_copy) can read a torn scoreboard.

This is a correctness regression from the 8.6 begin/commit split (8.3 has no such split — it uses a single fpm_scoreboard_update()), not a memory-safety issue: the scoreboard is a fixed shared struct of scalars, so the consequences are limited to garbled status/metrics and a possible writer-lock imbalance.

Suggested fix

Add the matching fpm_scoreboard_update_begin(NULL) immediately before the commit in fpm_request_end() (after fpm_scoreboard_proc_release(proc)), so the writer lock is held across the shared-counter update. Placing begin right before commit (rather than at function entry, as the other sites do) avoids leaking the writer lock on the proc == NULL early-return path. PR to follow.

PHP Version

PHP-8.6 branch at 47abe238897 (PHP 8.6.2-dev (fpm-fcgi), NTS DEBUG).

Operating System

Linux

主要语言
C
星标
41.9k
派生
8.5k
平均合并
2 天 16 小时
30 天内合并 PR
117

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。