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

Open Beginner friendly
#26,066 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, php
Domain
backend

Research direction

Read sapi/fpm/fpm/fpm_request.c around fpm_request_end() and compare its scoreboard calls with the begin/commit pairs in the same file. Check the lock behavior in sapi/fpm/fpm/fpm_scoreboard.c; the issue identifies the missing call and its safe placement after fpm_scoreboard_proc_release(proc). Done when request end acquires the writer lock before committing, with the proc == NULL return path unchanged.

Written by the indexing model from the issue text.

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

Dominant language
C
Stars
41.9k
Forks
8.5k
Avg merge
2d 16h
Merged PRs (30d)
117

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from php/php-src

All issues in php/php-src

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.