Repository navigation
Conversation
php_request_shutdown() only calls RSHUTDOWN once every RINIT returned, so the modules activated before a failing one never released their request state. With session.auto_start, the session stayed locked and every later request for it blocked forever in persistent SAPIs.
dunglas
force-pushed
the
rinit-bailout-rshutdown
branch
from
November 20, 2026 14:33
875fb4a to
1367bbb
Compare
henderkes
reviewed
Nov 20, 2026
dunglas
added a commit
to php/frankenphp
that referenced
this pull request
Nov 20, 2026
After a RINIT bailout, php_request_shutdown() skips every RSHUTDOWN. Since php/php-src@6b197ee4edf, mbstring's next RINIT frees the stale detect order list, which corrupts the heap. The Homebrew debug build used on macOS CI aborts with "zend_mm_heap corrupted (double free)". Fixed upstream by php/php-src#25157.
Member
|
can the following test be added ? --TEST--
A request whose startup bails out after session.auto_start with session.use_trans_sid
--EXTENSIONS--
session
zend_test
--INI--
default_socket_timeout=5
--FILE--
<?php
include __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc";
$args = [
'-d', 'extension_dir=' . ini_get('extension_dir'),
'-d', 'session.auto_start=1',
'-d', 'session.use_trans_sid=1',
'-d', 'session.use_cookies=0',
'-d', 'session.use_only_cookies=0',
'-d', 'session.save_path=' . __DIR__,
'-d', 'zend_test.bailout_in_rinit=1',
];
$builtin = shell_exec(escapeshellarg(getenv('TEST_PHP_EXECUTABLE') ?: PHP_BINARY) . ' -n -m');
foreach (['session', 'zend_test'] as $ext) {
if (!preg_match("/^$ext$/m", $builtin)) {
array_push($args, '-d', "extension=$ext");
}
}
php_cli_server_start('echo session_id();', null, $args);
$url = 'http://' . PHP_CLI_SERVER_ADDRESS . '/?PHPSESSID=rinitbailouttranssid';
var_dump(@file_get_contents($url));
var_dump(@file_get_contents($url));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/sess_rinitbailouttranssid');
?>
--EXPECT--
string(0) ""
string(20) "rinitbailouttranssid" |
Calling RSHUTDOWN from zend_activate_modules() ran it before the output buffers were flushed, so output handlers started by earlier RINITs ran after their module had shut down: a handler calling putenv() leaked the variable to the next request, and the session.use_trans_sid test failed. It also skipped the modules without RINIT. zend_activate_modules() now records how far it got, and zend_deactivate_modules() runs RSHUTDOWN at its usual step for every module except the one that bailed out and those whose RINIT never ran.
dunglas
added a commit
to php/frankenphp
that referenced
this pull request
Nov 21, 2026
Skips part of `TestRegisterExtension` on PHP 8.6 until php/php-src#25157 is released.
Member
Author
|
@devnexen done |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This prevents issues such as session files never closed with
session.auto_start=1.When a RINIT bails out,
php_request_shutdown()skips every RSHUTDOWN, including those of the modules whose RINIT already ran. Their request state leaks into the next request. For instance, the session stays locked and every later request for it blocks in persistent SAPIs (mod_php, FrankenPHP, the CLI server).zend_activate_modules()now records how far it got in a thread-local pointer.zend_deactivate_modules()then runs RSHUTDOWN at its usual step, after the output buffers are flushed, for every module except the one whose RINIT bailed out and the modules after it that have a RINIT. Modules without RINIT get their RSHUTDOWN as usual. There is no new API:zend_deactivate_modules()does nothing when no RINIT ran in the request. The cost on the normal path is one thread-local write per module with a RINIT.Tests:
ext/session/tests/rinit_bailout_releases_lock.phpt: the session lock is released.ext/session/tests/rinit_bailout_releases_lock_trans_sid.phpt(suggested by devnexen): same withsession.use_trans_sid, whose output handler runs during the flush.ext/zend_test/tests/rinit_bailout_rshutdown_after_output.phpt: an output handler callingputenv()during the flush doesn't leak the variable to the next request.Open question: exit instead?
A RINIT returning
FAILUREalready callsexit(1), and a bailout in RSHUTDOWN calls_exit(1)("module shutdown is incomplete"). A RINIT bailout is the only case where the process keeps serving. The alternative to this patch is to exit there too:session.auto_start=1, becomes a crash loop instead of failed requests.I went with recovery, but I'm happy to switch to exiting if you prefer.
Patch written with the assistance of Claude.