Repository navigation
Fix GH-23859: Reset map pointer watermark in accel_activate() #24644
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
Open
aasul
wants to merge
2
commits into
php:PHP-8.4
Choose a base branch
from
aasul:fix/gh23859-opcache-reset-84
base: PHP-8.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| --TEST-- | ||
| FPM: GH-23859 (Preloaded map pointers survive compilation and OPcache restarts) | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --SKIPIF-- | ||
| <?php include "skipif.inc"; ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| require_once "tester.inc"; | ||
|
|
||
| $cfg = <<<EOT | ||
| [global] | ||
| error_log = {{FILE:LOG}} | ||
| [worker] | ||
| listen = {{ADDR[worker]}} | ||
| pm = static | ||
| pm.max_children = 1 | ||
| [reset] | ||
| listen = {{ADDR[reset]}} | ||
| pm = static | ||
| pm.max_children = 1 | ||
| EOT; | ||
|
|
||
| $code = <<<'EOT' | ||
| <?php | ||
| if (PreloadedChild::$value !== 7 || PreloadedChild::$items !== ['initial'] | ||
| || PreloadedChild::step() !== 8 || preloaded_step() !== 13 | ||
| || PreloadedEnum::cases() !== [PreloadedEnum::A] | ||
| || (new ReflectionClass(PreloadedMutable::class))->getDefaultProperties() !== ['item' => 11]) { | ||
| throw new Exception('Preloaded state was not reset'); | ||
| } | ||
| PreloadedChild::$value = 23; | ||
| PreloadedChild::$items[] = 'changed'; | ||
|
|
||
| /* Persist new code and load a saved preload script after filling preload slots. */ | ||
| require __DIR__ . '/gh23859-preload.compile.inc'; | ||
| require __DIR__ . '/gh23859-preload.saved.inc'; | ||
| if (PreloadedChild::$value !== 23 || PreloadedChild::$items !== ['initial', 'changed'] | ||
| || PreloadedChild::step() !== 25 || preloaded_step() !== 15 | ||
| || PreloadedChild::compute() !== 13 || RequestChild::run() !== 20 | ||
| || request_step() !== 1 || saved_step() !== 1 | ||
| || PreloadedEnum::cases() !== [PreloadedEnum::A]) { | ||
| throw new Exception('Compilation corrupted preloaded state'); | ||
| } | ||
| echo 'ok'; | ||
| EOT; | ||
|
|
||
| $tester = new FPM\Tester($cfg, $code); | ||
| $preloadFile = $tester->getPrefixedFile('preload.inc'); | ||
| file_put_contents($preloadFile, <<<'EOT' | ||
| <?php | ||
| trait PreloadedTrait { | ||
| public static function step(): int { | ||
| static $n = 0; | ||
| return ++$n + self::$value; | ||
| } | ||
| } | ||
| class PreloadedBase { | ||
| public static int $value = 7; | ||
| public const VALUE = 11; | ||
| } | ||
| class PreloadedChild extends PreloadedBase { | ||
| use PreloadedTrait; | ||
| public static array $items = ['initial']; | ||
| public static function compute(): int { | ||
| return self::VALUE + count(self::$items); | ||
| } | ||
| } | ||
| function preloaded_step(): int { | ||
| static $n = 0; | ||
| return ++$n + PreloadedChild::compute(); | ||
| } | ||
| enum PreloadedEnum { case A; } | ||
| trait PreloadedMutable { public $item = PreloadedBase::VALUE; } | ||
| opcache_compile_file(__DIR__ . '/gh23859-preload.saved.inc'); | ||
| PreloadedChild::step(); | ||
| preloaded_step(); | ||
| PreloadedChild::$value = 99; | ||
| EOT); | ||
| file_put_contents($tester->getPrefixedFile('compile.inc'), <<<'EOT' | ||
| <?php | ||
| class RequestChild extends PreloadedChild { | ||
| public static int $other = 19; | ||
| public static function run(): int { static $n = 0; return ++$n + self::$other; } | ||
| } | ||
| function request_step(): int { static $n = 0; return ++$n; } | ||
| EOT); | ||
| file_put_contents($tester->getPrefixedFile('saved.inc'), <<<'EOT' | ||
| <?php | ||
| static $n = 0; | ||
| if (++$n !== 1) { | ||
| throw new Exception('Saved script static variables were not reset'); | ||
| } | ||
| if (!function_exists('saved_step')) { | ||
| function saved_step(): int { static $n = 0; return ++$n; } | ||
| } | ||
| EOT); | ||
| $resetFile = $tester->getPrefixedFile('reset.src.php'); | ||
| file_put_contents($resetFile, <<<'EOT' | ||
| <?php | ||
| if (isset($_GET['reset'])) { | ||
| var_dump(opcache_reset()); | ||
| } else { | ||
| echo opcache_get_status(false)['opcache_statistics']['manual_restarts']; | ||
| } | ||
| EOT); | ||
|
|
||
| $opcache = ini_get('extension_dir') . DIRECTORY_SEPARATOR . 'opcache.' . PHP_SHLIB_SUFFIX; | ||
| $extraArgs = is_file($opcache) ? ['-dzend_extension=' . $opcache] : []; | ||
| $iniEntries = [ | ||
| 'opcache.enable' => '1', | ||
| 'opcache.file_update_protection' => '0', | ||
| 'opcache.preload' => $preloadFile, | ||
| ]; | ||
| if (getenv('TEST_FPM_RUN_AS_ROOT')) { | ||
| $iniEntries['opcache.preload_user'] = 'root'; | ||
| } | ||
| $tester->start($extraArgs, iniEntries: $iniEntries); | ||
| $tester->expectLogStartNotices(); | ||
| $tester->request(address: '{{ADDR[reset]}}', scriptFilename: $resetFile)->expectBody('0'); | ||
| $tester->request(address: '{{ADDR[worker]}}')->expectBody('ok'); | ||
| $tester->request(address: '{{ADDR[worker]}}')->expectBody('ok'); | ||
|
|
||
| for ($i = 1; $i <= 3; $i++) { | ||
| $tester->request(query: 'reset=1', address: '{{ADDR[reset]}}', scriptFilename: $resetFile) | ||
| ->expectBody('bool(true)'); | ||
| $tester->request(address: '{{ADDR[reset]}}', scriptFilename: $resetFile)->expectBody((string) $i); | ||
| $tester->request(address: '{{ADDR[worker]}}')->expectBody('ok'); | ||
| $tester->request(address: '{{ADDR[worker]}}')->expectBody('ok'); | ||
| } | ||
|
|
||
| $tester->terminate(); | ||
| $tester->expectLogTerminatingNotices(); | ||
| $tester->close(); | ||
|
|
||
| ?> | ||
| Done | ||
| --EXPECT-- | ||
| Done | ||
| --CLEAN-- | ||
| <?php | ||
| require_once "tester.inc"; | ||
| FPM\Tester::clean(); | ||
| foreach (['preload', 'compile', 'saved'] as $file) { | ||
| @unlink(__DIR__ . '/gh23859-preload.' . $file . '.inc'); | ||
| } | ||
| @unlink(__DIR__ . '/gh23859-preload.reset.src.php'); | ||
| ?> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| --TEST-- | ||
| FPM: GH-23859 (Map pointers grow after OPcache restarts in another worker) | ||
| --EXTENSIONS-- | ||
| opcache | ||
| zend_test | ||
| --SKIPIF-- | ||
| <?php include "skipif.inc"; ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| require_once "tester.inc"; | ||
|
|
||
| $cfg = <<<EOT | ||
| [global] | ||
| error_log = {{FILE:LOG}} | ||
| [worker] | ||
| listen = {{ADDR[worker]}} | ||
| pm = static | ||
| pm.max_children = 1 | ||
| [reset] | ||
| listen = {{ADDR[reset]}} | ||
| pm = static | ||
| pm.max_children = 1 | ||
| EOT; | ||
|
|
||
| $code = <<<'EOT' | ||
| <?php | ||
| class Test { | ||
| public static function run() { | ||
| static $i = 0; | ||
| return ++$i; | ||
| } | ||
| } | ||
| if (Test::run() !== 1) { | ||
| throw new Exception('Static variables were not reset'); | ||
| } | ||
| echo zend_get_map_ptr_last(); | ||
| EOT; | ||
|
|
||
| $tester = new FPM\Tester($cfg, $code); | ||
| $resetFile = $tester->getPrefixedFile('reset.src.php'); | ||
| file_put_contents($resetFile, <<<'EOT' | ||
| <?php | ||
| if (isset($_GET['reset'])) { | ||
| var_dump(opcache_reset()); | ||
| } else { | ||
| echo opcache_get_status(false)['opcache_statistics']['manual_restarts']; | ||
| } | ||
| EOT); | ||
|
|
||
| $opcache = ini_get('extension_dir') . DIRECTORY_SEPARATOR . 'opcache.' . PHP_SHLIB_SUFFIX; | ||
| $extraArgs = is_file($opcache) ? ['-dzend_extension=' . $opcache] : []; | ||
| $tester->start($extraArgs, extensions: ['zend_test'], iniEntries: [ | ||
| 'opcache.enable' => '1', | ||
| 'opcache.file_update_protection' => '0', | ||
| ]); | ||
| $tester->expectLogStartNotices(); | ||
| $tester->request(address: '{{ADDR[reset]}}', scriptFilename: $resetFile)->expectBody('0'); | ||
| $before = $tester->request(address: '{{ADDR[worker]}}')->getBody(); | ||
| if (!is_numeric($before)) { | ||
| throw new Exception('Invalid map pointer count'); | ||
| } | ||
| $tester->request(address: '{{ADDR[worker]}}')->expectBody($before); | ||
|
|
||
| /* Complete each restart in the other pool before the stale worker persists again. */ | ||
| for ($i = 1; $i <= 3; $i++) { | ||
| $tester->request(query: 'reset=1', address: '{{ADDR[reset]}}', scriptFilename: $resetFile) | ||
| ->expectBody('bool(true)'); | ||
| $tester->request(address: '{{ADDR[reset]}}', scriptFilename: $resetFile)->expectBody((string) $i); | ||
| $tester->request(address: '{{ADDR[worker]}}')->expectBody($before); | ||
| $tester->request(address: '{{ADDR[worker]}}')->expectBody($before); | ||
| } | ||
|
|
||
| $tester->terminate(); | ||
| $tester->expectLogTerminatingNotices(); | ||
| $tester->close(); | ||
|
|
||
| ?> | ||
| Done | ||
| --EXPECT-- | ||
| Done | ||
| --CLEAN-- | ||
| <?php | ||
| require_once "tester.inc"; | ||
| FPM\Tester::clean(); | ||
| @unlink(__DIR__ . '/gh23859.reset.src.php'); | ||
| ?> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.