rhubarbgroup / redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.
https://wordpress.org/plugins/redis-cache/
GNU General Public License v3.0
428 stars 149 forks source link

NGINX & PHP-FPM crashes when activating or enabling cache #547

Closed mkvae7 closed 1 week ago

mkvae7 commented 1 week ago

Description

Whenever I activate, deactive or enable redis cache on plugin page, the services nginx and fpm crashes. I have to manually restart both services.

Expected Behavior

It shouldn't throw 502 error.

Actual Behavior

It crashes instantly. Logs seems empty with no corresponding to the behavior or pointing to.

Possible Fix

Couldn't find any.

Steps to Reproduce

  1. login to wp-admin
  2. activate/deactivate plugin
  3. error 502
  4. restart php8.3-fpm & nginx services to restore production website to running state.

Additional context

It started all suddenly, I tried fresh nginx conf. Even upgraded and downgraded php-fpm versions. No help.

Environment

I'm running the VPS on Debian. 4 cpres and 8GB RAM. Here's nginx.conf:

NGINX.conf:

user www-data; worker_processes auto; pid /run/nginx.pid; error_log /var/log/nginx/error.log; include /etc/nginx/modules-enabled/*.conf; worker_rlimit_nofile 100000; events { worker_connections 4096; use epoll; multi_accept on; }

http {

# Basic Settings
##
tcp_nodelay on;
types_hash_max_size 2048;
client_max_body_size 500M; # allows file uploads up to 500 megabytes
    # performance boosts for PHP
    sendfile                        on;
    tcp_nopush                      off;

    # proxy buffers - no 502 errors!
    proxy_buffer_size               128k;
    proxy_buffers                   4 256k;
    proxy_busy_buffers_size         256k;

    # fastcgi buffers - no 502 errors!
    fastcgi_buffering               on;
    fastcgi_buffer_size             16k;
    fastcgi_buffers                 16 16k;

    # max timeouts (should match php.ini)
    fastcgi_connect_timeout         600s;
    fastcgi_send_timeout            600s;
    fastcgi_read_timeout            600s;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
##
# Gzip Settings
##
gzip on;
gzip_min_length 10240;
gzip_comp_level 1;
gzip_vary on;
gzip_disable mie6;
gzip_proxied expired no-cache no-store private auth;
    gzip_types
    # text/html is always compressed by HttpGzipModule
    text/css
        text/javascript
        text/xml
        text/plain
        text/x-component
        application/javascript
        application/x-javascript
        application/json
        application/xml
        application/rss+xml
        application/atom+xml
        font/truetype
        font/opentype
        application/vnd.ms-fontobject
        image/svg+xml;
reset_timedout_connection on;
client_body_timeout 45;
send_timeout 50;
keepalive_timeout 50;
keepalive_requests 150;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.*;

}

Website in sites-enabled .conf causing issue:

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MPWP:10m; proxy_cache_path /etc/nginx/cache1 levels=1:2 keys_zone=MPWP1:10m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; add_header X-Cache $upstream_cache_status;

server { server_name WEB-SITE.ae WEB-SITE.com; root /var/www/html/wordpress; index index.html index.htm index.nginx-debian.html index.php;

#Cache everything by default
set $no_cache 0;
#Don't cache POST requests
if ($request_method = POST)
{
    set $no_cache 1;
}
#Don't cache if the URL contains a query string
if ($query_string != "")
{
    set $no_cache 1;
}
#Don't cache the following URLs
if ($request_uri ~* "/(wp-admin/|login.php)")
{
    set $no_cache 1;
}
#Don't cache if there is a cookie called PHPSESSID
if ($http_cookie = "PHPSESSID")
{
    set $no_cache 1;
}

location ~* .(jpg|jpeg|gif|png|css|bmp|js|ico|ogg|mp3|flv|svg|webp)$ { root /var/www/html/wordpress; expires 1y; add_header X-Cache $upstream_cache_status; add_header Pragma "public"; add_header Cache-Control "max-age=2592000, public, must-revalidate, proxy-revalidate";
fastcgi_cache MPWP; fastcgi_cache_valid 200 1h; fastcgi_cache_key "\$scheme\$request_method\$host\$request_uri"; }

location / { try_files $uri $uri/ /index.php$is_args$args; log_not_found off; }

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/$fastcgi_script_name;
    include fastcgi_params;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
    # performance boosts for PHP
    sendfile                        on;
    tcp_nopush                      off;
    keepalive_requests              0;
    # proxy buffers - no 502 errors!
    proxy_buffer_size               128k;
    proxy_buffers                   4 256k;
    proxy_busy_buffers_size         256k;
    # fastcgi buffers - no 502 errors!
    fastcgi_buffering               on;
    fastcgi_buffer_size             16k;
    fastcgi_buffers                 16 16k;
    # max timeouts (should match php.ini)
    fastcgi_connect_timeout         600s;
    fastcgi_send_timeout            600s;
    fastcgi_read_timeout            600s;
log_not_found off;
proxy_ignore_headers Cache-Control Set-Cookie;
    if ($request_uri ~* "xmlrpc.php|wp-cron.php|robots.txt|/wp-content/upgrade|/wp-content/backups-dup-pro|/wp-content/wp-cloudflare-super-page-cache|/wp-content/jetpack-waf|theme.php|phpmemtest.php|502_recovery_point.php|info.php|xmlrpc.php|wp-.*.php|/wp-admin/|/admin-*|wp-cron|/shopping-cart/|/checkout-3/|/my-account/"){
     set $no_cache 1;
    }
}

location ~ .(xml|xsl)$ { log_not_found off; add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; } location /robots.txt { add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; } location ~ .(css|js|pdf)$ { add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, max-age=2592000, stale"; } location ~* .(jpg|jpeg|png|gif|ico|eot|swf|svg|webp|avif|ttf|otf|woff|woff2|ogg|mp4|mpeg|avi|mkv|webm|mp3)$ { expires 30d; add_header Cache-Control "public, no-transform";} location /wp-cron.php { add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; }

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/WEB-SITE.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/WEB-SITE.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

===========================

Please help.

E-VANCE commented 1 week ago

Same experience here... We encounter the following kernel error after having updated the plugin to the most recent version:

php-fpm8.2[3813316]: segfault at 18 ip 00005592fed8fbd0 sp 00007ffffd604de0 error 4 in php-fpm8.2[5592feb10000+313000]

Disabling the object cache & restarting php8.2-fpm resolves the issue but it re-instates immediately after re-activiation.

Please advise.

yatsukhnenko commented 1 week ago

The segfault is probably caused by PHP extension (eg PhpRedis) which plugin utilizes

E-VANCE commented 1 week ago

The segfault is probably caused by PHP extension (eg PhpRedis) which plugin utilizes

Thanks for your input!

mkvae7 commented 1 week ago

I solved the issue.

It was Opcache itself (not JIT). I disabled it, tested. Flushing/disabling/enabling redis cache works without issues.

I then enabled it again, and started blacklisting wordpress folder. It worked. I kept working a list (took time) for files and folders to be black-listed.

so better edit opcache.ini file in /etc/php/8.*/fpm/conf.d/ and add this line: opcache.blacklist_filename=/etc/php/8.2/fpm/conf.d/opcache-blacklist.txt

in the blacklist file, here's the list I came up with: /var/www/html/wordpress/wp-content/object-cache.php /var/www/html/wordpress/wp-content/wpo/cache /var/www/html/wordpress/wp-content/cache/ /var/www/html/wordpress/wp-content/advanced-cache.php /var/www/html/wordpress/wp-content/backups-dup-pro/ /var/www/html/wordpress/wp-content/plugins/nasa-core/ /var/www/html/wordpress/wp-content/plugins/duplicator-pro/ /var/www/html/wordpress/wp-content/plugins/redis-cache/ /var/www/html/wordpress/wp-content/db.php /var/www/html/wordpress/wp-content/docket-cache-data/ /var/www/html/wordpress/wp-content/plugins/*

While this is temporary solution, for now it works without issues. Just thought of passing the info instead of ghosting and not giving fellow developers the info needed.