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

Ouverte Adaptée aux débutants
#26,066 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
88/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
c, php
Domaine
backend

Piste de recherche

Lisez sapi/fpm/fpm/fpm_request.c autour de fpm_request_end() et comparez ses appels au scoreboard avec les paires begin/commit dans le même fichier. Vérifiez le comportement du verrou dans sapi/fpm/fpm/fpm_scoreboard.c ; l’issue identifie l’appel manquant et son emplacement sûr après fpm_scoreboard_proc_release(proc). Le travail est terminé lorsque request end acquiert le verrou en écriture avant de valider, tandis que le chemin de retour proc == NULL reste inchangé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
C
Étoiles
41.9k
Forks
8.5k
Merge moyen
2 j 16 h
PR mergées (30 j)
117

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de php/php-src

Toutes les issues de php/php-src

Issues similaires

Plus d'issues C

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.