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

オープン 初心者向け
#26,066 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, php
領域
backend

調査の方向性

sapi/fpm/fpm/fpm_request.cでfpm_request_end()の周辺を読み、同じファイル内の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時間
マージ済み PR(30日)
117

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

php/php-src のほかの issue

php/php-src の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。