Skip to content

opcache.consistency_checks > 0 causes segfaults in PHP >= 8.1.5 in fpm context #8065

Closed

Description

@CyberLine

Description

After upgrading some projects to PHP 8.1.0 and 8.1.2 we could see requests getting slower and slower over time. Restart of the correspondig fpm-pool fixed that for short. After digging in the problem we could isolate and reproduce it:

  • use a Debian 10 or 11 maschine and install php8.1-fpm and php8.1-opcache.
  • modify opcache.ini:
zend_extension=opcache.so

[opcache]
opcache.consistency_checks=1
  • require laminas: composer require laminas/laminas-servicemanager
  • create a test script (we use laminas-servicemanager here):
<?php

declare(strict_types=1);

chdir(dirname(__DIR__));
require 'vendor/autoload.php';

use Laminas\ServiceManager\ServiceManager;
$container = new ServiceManager();
  • call that script in a loop 1000 or more times while running htop in another terminal:
    for i in {1..10000}; do curl localhost/test.php; done;

You would see an increment usage of memory that will not getting freed after all. Set opcache.consistency_checks to 0 to check that it will not keep any used memory.

PHP Version

8.1.0

Operating System

Debian 10/11

Activity

  1. cmb69 commented on Feb 9, 2022

    @cmb69
    Member

    Do you get any "Checksum failed for" log entries, if you set opcache.error_log=… and opcache.log_verbosity_level=4?

  2. CyberLine commented on Feb 9, 2022

    @CyberLine
    Author
    Wed Feb  9 15:15:47 2022 (222625): Message Checksum failed for '/home/alexander/test/vendor/laminas/laminas-config-aggregator/src/PhpFileProvider.php':  expected=0x68e34d40, found=0x35584fc2
    Wed Feb  9 15:15:47 2022 (222625): Message Cached script '/home/alexander/test/vendor/laminas/laminas-config-aggregator/src/PhpFileProvider.php'
    Wed Feb  9 15:15:47 2022 (222625): Message Added key '/home/alexander/test/vendor/composer/../laminas/laminas-config-aggregator/src/PhpFileProvider.php'
    Wed Feb  9 15:15:47 2022 (222625): Message Checksum failed for '/home/alexander/test/vendor/laminas/laminas-servicemanager/src/ServiceManager.php':  expected=0x76daed23, found=0x478bef0e
    Wed Feb  9 15:15:47 2022 (222625): Message Cached script '/home/alexander/test/vendor/laminas/laminas-servicemanager/src/ServiceManager.php'
    Wed Feb  9 15:15:47 2022 (222625): Message Added key '/home/alexander/test/vendor/composer/../laminas/laminas-servicemanager/src/ServiceManager.php'
    Wed Feb  9 15:15:47 2022 (222625): Message Checksum failed for '/home/alexander/test/vendor/laminas/laminas-servicemanager/src/ServiceLocatorInterface.php':  expected=0xb598eac3, found=0x7ae8ecda
    Wed Feb  9 15:15:47 2022 (222625): Message Cached script '/home/alexander/test/vendor/laminas/laminas-servicemanager/src/ServiceLocatorInterface.php'
    Wed Feb  9 15:15:47 2022 (222625): Message Added key '/home/alexander/test/vendor/composer/../laminas/laminas-servicemanager/src/ServiceLocatorInterface.php'
    Wed Feb  9 15:15:47 2022 (222625): Message Checksum failed for '/home/alexander/test/vendor/container-interop/container-interop/src/Interop/Container/ContainerInterface.php':  expected=0x20efdca4, found=0x5182df08
    Wed Feb  9 15:15:47 2022 (222625): Message Cached script '/home/alexander/test/vendor/container-interop/container-interop/src/Interop/Container/ContainerInterface.php'
    Wed Feb  9 15:15:47 2022 (222625): Message Added key '/home/alexander/test/vendor/composer/../container-interop/container-interop/src/Interop/Container/ContainerInterface.php'
    
  3. cmb69 commented on Feb 9, 2022

    @cmb69
    Member

    Thanks!

    If the checksum comparison fails, the file is compiled again, and the old oparray is not freed – that is by design, to avoid copying shared memory. As such, this doesn't look like a bug, but I wonder why the checksum comparison fails in the first place. Are these files modified during script execution?

  4. CyberLine commented on Feb 9, 2022

    @CyberLine
    Author

    Are these files modified during script execution?

    No, they aren't. You can run the same code on PHP 7.4 or 8.0 without "Checksum failed" error 🤷

    Same output with php7.4 or 8.0:

    Wed Feb  9 15:32:07 2022 (222628): Message Cached script '/home/alexander/test/vendor/laminas/laminas-servicemanager/src/ServiceManager.php'
    Wed Feb  9 15:32:07 2022 (222628): Message Added key '/home/alexander/workspace/test/vendor/composer/../laminas/laminas-servicemanager/src/ServiceManager.php'
    Wed Feb  9 15:32:07 2022 (222628): Message Cached script '/home/alexander/test/vendor/laminas/laminas-servicemanager/src/ServiceLocatorInterface.php'
    Wed Feb  9 15:32:07 2022 (222628): Message Added key '/home/alexander/test/vendor/composer/../laminas/laminas-servicemanager/src/ServiceLocatorInterface.php'
    Wed Feb  9 15:32:07 2022 (222628): Message Cached script '/home/alexander/test/vendor/psr/container/src/ContainerInterface.php'
    Wed Feb  9 15:32:07 2022 (222628): Message Added key '/home/alexander/test/vendor/composer/../psr/container/src/ContainerInterface.php'
    Wed Feb  9 15:32:07 2022 (222628): Message Cached script '/home/alexander/test/vendor/container-interop/container-interop/src/Interop/Container/ContainerInterface.php'
    Wed Feb  9 15:32:07 2022 (222628): Message Added key '/home/alexander/test/vendor/composer/../container-interop/container-interop/src/Interop/Container/ContainerInterface.php'
    
  5. 34 remaining items

  6. added 3 commits that reference this issue on Mar 1, 2023
    91e64af
    9314ef8
  7. added 2 commits that reference this issue on Mar 7, 2023
    7682868
    b39ff33
  8. added a commit that references this issue on Feb 3, 2024
    85df512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions