-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #78413: php-fpm request_terminate_timeout does not take effect af… #4637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make the timeout also apply in the
FINISHED
state. Is that right?Additionally this also controls the slow log behavior...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. That was the intention.
proc.request_stage
will be set to FINISHED either:php_execute_script
finished executing current script, a call tofpm_request_end
is made which in turn sets FPM_REQUEST_FINISHEDfastcgi_finish_request
if FastCGI keep-alive is not active (as far as I know none of major webservers implement FastCGI keep-alive) via callchain:fastcgi_finish_request
->fcgi_close
->if (... !req->keep ... )
->req->hook.on_close
=fpm_request_finished
-> FPM_REQUEST_FINISHED.And because requests in FPM_REQUEST_FINISHED are no longer tracked for timeout, this creates an opportunity for PHP code to seize control of worker process for arbitrary amount of time.
In addition to
fastcgi_finish_request
, there is another way to exploit this bug by using shutdown functions (viaregister_shutdown_function
) since shutdown handlers are called inphp_request_shutdown
which is called when request stage is already FINISHED.After a careful review I came to conclusion that I might need to add a check for
proc.request_stage <= FPM_REQUEST_FINISHED
just in case if some newer states will be added in future... What do you think? But from the other hand it will create a possibility to evade timeout timits in future ...Slow log explicitly checks for
proc.request_stage == FPM_REQUEST_EXECUTING
so that even if we broaden set of request stages in parentif
it will be ok.php-src/sapi/fpm/fpm/fpm_request.c
Lines 254 to 257 in 1ac6b02