Search code examples
dockernginxyii2opcachephp-7.4

Yii2 app causes connection reset by peer after upgrade to php 7.4 with opcache activated


We have a large yii2 application, which ran perfectly in a Debian Docker container with nginx + PHP-FPM 7.3 and opcache enabled.

After upgrading to PHP 7.4.10, some requests result in '(Connection reset by peer) while reading response header from upstream' errors. Disabling opcache solves the problem, but this is not really an option. I can also leave opcache enabled and blacklist the whole yii2 vendor folder, but this is also not an option.

We have also a non-docker PHP-FPM 7.4 + nginx + opcache installation on a Debian VM, this seam to run so far without such errors. But we need the Docker environment for development and later switching to docker in production.

Running the tests with PHP 7.3 + opcache took about 12 minutes, now without opcache 30 minutes(!).

I tried and was not successful:

  • using the official Yii2 docker image
  • using the official PHP 7.4.10 apache image
  • using the official PHP-FPM 7.4.10 with latest Nginx image
  • Using lower versions of docker than 'Docker version 19.03.12-ce, build 48a66213fe'
  • setting several parameters in different variants in nginx, opcache and php, I found in the net like ignoring invalid headers for nginx.
  • Downgrading the PHP version to 7.4.9 or 7.4.2.
  • Trying to find and fix the error causing code in our code base, but in the most cases just the resulting content just changed, mean the same controller action runs with and without an error, while only the content has changed. Headers and HTTP return code were the same.

We have the problem on all of our developer machines, like Mac notebooks, Windows notebooks and Linux notebooks using Ubuntu or Fedora.

My environment:

  • OS: 5.7.19-2-MANJARO
  • Docker: 19.03.12-ce, build 48a66213fe
  • CPU: Intel i7-1065G7
  • RAM: 16 GB
  • SSD: 512 GB PCIe NVMe M.2

If anyone has some suggestions and even know how to solve the issue.

Update:

I configured my local system to run php-fpm 7.4.10 and configured the nginx in the docker container to use my local (on host) php-fpm. I got no errors or “Connection reset by peer” events.

So for me it seams to be a problem with docker and opcache.

Does anyone know what yii2 is doing when opcache is enabled and maybe how configure it?

Update: Now I also have back trace from gdb for the segmentation fault:

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `php-fpm: pool www                                                          '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  zend_gc_delref (p=0x6341203a79726156) at ./Zend/zend_types.h:1041
1041    ./Zend/zend_types.h: No such file or directory.
(gdb) bt
#0  zend_gc_delref (p=0x6341203a79726156) at ./Zend/zend_types.h:1041
#1  i_zval_ptr_dtor (zval_ptr=<optimized out>) at ./Zend/zend_variables.h:43
#2  zval_ptr_dtor (zval_ptr=<optimized out>) at ./Zend/zend_variables.c:84
#3  0x000055fd4809a88c in user_shutdown_function_dtor (zv=<optimized out>) at ./ext/standard/basic_functions.c:5048
#4  0x000055fd48177a25 in zend_hash_destroy (ht=0x7f961acb1150) at ./Zend/zend_hash.c:1541
#5  0x000055fd480a0515 in php_free_shutdown_functions () at ./ext/standard/basic_functions.c:5174
#6  0x000055fd48106445 in php_request_shutdown (dummy=<optimized out>) at ./main/main.c:1905
#7  0x000055fd47fd14dd in main (argc=<optimized out>, argv=<optimized out>) at ./sapi/fpm/fpm/fpm_main.c:1970

Solution

  • The back trace lead me to the solution, it is the pcov module.

    Disabling it did the trick.

    I was mislead by search result for segmentation faults which pointed to opcache and the changes made to opcache in PHP 7.4 and the pcov module was also enabled when using PHP 7.3 + opcache.

    For now I'm lucky it works again with the new PHP version-

    As we only need pcov to generate code coverage reports and we can disable opcache for code coverage report creation.

    If anyone knows more about pcov + opcache + PHP 7.4, please leave a comment.