ZTS with --disable-zend-signals: execution timeout delivered to a non-PHP thread is lost and kills the process

オープン
#25,548 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c
領域
backend

調査の方向性

Start by reading zend_timeout_handler() and the signal forwarding path used by pcntl_signal_handler() for ZTS builds with --disable-zend-signals; the issue does not name source files or tests. Reproduce on the described macOS arm64 setup using the provided script and the zend_test_raise_on_foreign_thread() helper from GH-25542. Done means the timeout produces the expected PHP fatal error instead of losing the signal and terminating the process with SIGALRM.

索引モデルが issue の本文から書いたものです。

説明

Description

On a ZTS build configured with --disable-zend-signals, the execution timeout signal can be delivered to a thread that never ran PHP, such as a libdispatch worker on macOS. zend_timeout_handler() then prints a message and returns without setting EG(timed_out), so the timeout is lost. The handler is installed with SA_RESETHAND, so the signal's disposition is back to SIG_DFL and the next one terminates the process.

The script below needs zend_test_raise_on_foreign_thread(), which GH-25542 adds to zend_test. It raises the signal on a new thread, which makes the delivery deterministic.

<?php
set_time_limit(1);
zend_test_raise_on_foreign_thread(SIGALRM);
$end = hrtime(true) + 3_000_000_000;
while (hrtime(true) < $end);
echo "no timeout\n";

Resulted in this output (5 of 5 runs, process terminated by SIGALRM):

zend_timeout_handler() called in a thread not managed by PHP. The expected signal handler will not be called. This is probably a bug.

But I expected this output instead:

Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

With zend signals enabled, GH-25542 forwards the signal to the PHP thread and the script produces the expected fatal error. Without zend signals, only pcntl_signal_handler() forwards. zend_timeout_handler() does not, so this configuration is not covered.

SIGALRM is the timeout signal on macOS arm64. I have only tested this platform.

PHP Version

PHP-8.4 branch (8.4.29-dev), debug ZTS build with --disable-zend-signals, with GH-25542 applied for the test helper

Operating System

macOS (arm64)

主要言語
C
スター
41.8k
フォーク
8.6k
平均マージ
2日 15時間
マージ済み PR(30日)
125

環境構築

はじめの一歩

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

php/php-src のほかの issue

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

似ている issue

C の issue をもっと見る

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

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