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

We have 2 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 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.

I also observed in some cases a core dump is triggered due to segmentation fault.

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?

After creating a debug php image and tracing the segmentation faults, I found that pcov is causing the errors when opcache is enabled at the same time with PHP 7.4

Here is the corresponding back trace:

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
1 Like