php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78521 request_terminate_timeout does not take effect in shutdown handlers
Submitted: 2019-09-10 04:07 UTC Modified: 2019-09-30 10:56 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: turchanov at farpost dot com Assigned: nikic (profile)
Status: Closed Package: FPM related
PHP Version: 7.3.9 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: turchanov at farpost dot com
New email:
PHP Version: OS:

 

 [2019-09-10 04:07 UTC] turchanov at farpost dot com
Description:
------------
PHP shutdown handlers (registered via register_shutdown_function) are not tracked for request_terminate_timeout. 

This bug is related to bug #78413 due to the same underlying reasons. Request processing loop in fpm_main.c does this sequence of calls:
  while () {
     <get request>
     ...
     php_execute_script()
     ...
     fpm_request_end()  -> sets request stage to FPM_REQUEST_FINISHED
     ...
     php_request_shutdown() --> calls shutdown handlers
  }

and since request_termination_timeout is applied only to ((stage > FPM_REQUEST_ACCEPTING) && (stage < FPM_REQUEST_END)) it is effectively ignored.

This creates an opportunity for PHP code to seize control of worker process for an arbitrary amount of time.

Test script:
---------------
<?php

function func() {
    sleep(100000);
}

register_shutdown_function('func');


Expected result:
----------------
Php worker being terminated by fpm after %request_terminate_timeout% of execution time



Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-10 04:10 UTC] turchanov at farpost dot com
The following pull request has been associated:

Patch Name: Fix #78413: php-fpm request_terminate_timeout does not take effect af…
On GitHub:  https://github.com/php/php-src/pull/4637
Patch:      https://github.com/php/php-src/pull/4637.patch
 [2019-09-30 10:56 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-09-30 10:56 UTC] nikic@php.net
Fixed by linked PR:
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 08:01:35 2025 UTC