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

Aperta Adatta ai principianti
#26,066 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, php
Ambito
backend

Direzione di ricerca

Leggi sapi/fpm/fpm/fpm_request.c attorno a fpm_request_end() e confronta le chiamate allo scoreboard con le coppie begin/commit nello stesso file. Controlla il comportamento del lock in sapi/fpm/fpm/fpm_scoreboard.c; l’issue identifica la chiamata mancante e la sua collocazione sicura dopo fpm_scoreboard_proc_release(proc). Il lavoro è terminato quando request end acquisisce il lock di scrittura prima del commit e il percorso di ritorno proc == NULL rimane invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C
Stelle
41.9k
Fork
8.5k
Merge medio
2g 16h
PR unite (30g)
117

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di php/php-src

Tutte le issue di php/php-src

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.