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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
30 + 13 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC