ZTS: pcntl signal handled by one PHP thread ends the process or is lost when delivered elsewhere

未關閉
#25,549 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
43/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
c, php

研究方向

Start by tracing ZTS signal registration, delivery, and request shutdown in the PHP source; the issue names pcntl_signal(), RSHUTDOWN, zend signals, and the pthread embed SAPI reproduction, but no source files or tests. Reproduce both cases on a debug ZTS build, with and without --disable-zend-signals, and inspect the related GH-25542 and GH-10193 discussions. Done means a handler registered by one live PHP thread runs when either described signal delivery case occurs, without terminating the process or losing the signal.

由索引模型根據 Issue 內容生成。

描述

Description

Signal dispositions are process-wide, but under ZTS the PHP handler for a signal belongs to the thread that registered it. With several threads running PHP requests (an embedding application, for instance), a signal handled by one thread can end the process or be lost. GH-25542 fixes delivery to threads that never ran PHP, but these two cases remain.

1. A signal lands on a PHP thread that has no handler for it.

  1. Thread A runs a request and calls pcntl_signal(SIGUSR1, $handler).
  2. Thread B runs a request and has no handler for SIGUSR1.
  3. SIGUSR1 is delivered to thread B.

2. Two threads handle the same signal and one finishes first.

  1. Threads A and B each run a request and call pcntl_signal(SIGUSR1, $handler).
  2. Thread B finishes its request.
  3. SIGUSR1 is delivered to a thread that never ran PHP, while thread A is still running.

I reproduced both with a small embed SAPI program that runs each request on its own pthread and calls raise() on the target thread. Each result below is 10 of 10 runs, on a debug ZTS build:

Case With zend signals With --disable-zend-signals
1. PHP thread without a handler Process terminated by SIGUSR1 Signal lost, A's handler never runs
2. Same signal, one thread finished Process terminated by SIGUSR1 Process terminated by SIGUSR1

I expected thread A's handler to run in every case.

The results are the same with and without GH-25542. In case 2 without zend signals, thread B's RSHUTDOWN resets the signal to SIG_DFL for the whole process while thread A still relies on it.

This looks related to the discussion in GH-10193 about making the zend signal state process-wide rather than per thread.

PHP Version

PHP-8.4 branch (8.4.29-dev)

Operating System

macOS (arm64)

主要語言
C
星號
41.8k
分支
8.6k
平均合併
2 天 15 小時
30 天內合併 PR
125

環境準備

  • 沒有 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 摘要。