Opened 7 years ago

#1402 new defect

Not invalidate cahe if fastcgi_cache_background_update is on

Reported by: artemsuv@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.13.x
Keywords: fastcgi_cache_background_update, fastcgi_cache, STALE Cc:
uname -a: Linux 96f875ad0eb0 3.13.0-110-generic #157-Ubuntu SMP Mon Feb 20 11:54:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.13.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.2l 25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=owox --group=owox --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-openssl=openssl --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=njs-1c50334fbea6/nginx --add-module=nginx_modules/ngx_cache_purge --add-dynamic-module=nginx_modules/ngx_http_redis --add-dynamic-module=nginx_modules/redis2-nginx-module --add-dynamic-module=nginx_modules/ngx_http_geoip2_module --add-dynamic-module=nginx_modules/lua-nginx-module --add-dynamic-module=nginx_modules/lua-upstream-nginx-module --add-dynamic-module=nginx_modules/ngx_devel_kit --add-dynamic-module=nginx_modules/set-misc-nginx-module --add-dynamic-module=nginx_modules/ngx_small_light --add-dynamic-module=nginx_modules/owox-nginx-image-module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-debug

Description

Config of virtual host is:

log_format service_json '{ '
'\"request\": \"$request\", '
'\"status\": \"$status\", '
'\"body_bytes_sent\": \"$body_bytes_sent\", '
'\"http_referer\": \"$http_referer\", '
'\"uri\": \"$uri\", '
'\"args\": \"$args\", '
'\"upstream_cache_status\": \"$upstream_cache_status\", '
'\"upstream_response_time\": \"$upstream_response_time\", '
'\"request_time\": \"$request_time\", '
'\"http_user_agent\": \"$http_user_agent\", '
'\"cs\": \"$upstream_cache_status\" }';

fastcgi_cache_path /var/www/owox-bot-finder/cache levels=1:2 keys_zone=fastcgi_cache:64m max_size=2G inactive=2m;
fastcgi_cache_background_update on;


server {
    listen 80 default_server;
    server_name finder;
    root /var/www/finder;

    location / {

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param HTTPS off;


		fastcgi_cache fastcgi_cache;
		fastcgi_cache_key "$request_method|$scheme|$host|$uri";
		fastcgi_cache_use_stale updating error timeout invalid_header http_500 http_503;

		fastcgi_cache_valid 200 304 404 30s;
		fastcgi_cache_valid 301 30s;

		fastcgi_cache_lock on;
		fastcgi_cache_lock_timeout 25s;

	}

    #return 404 for all php files as we do have a front controller
    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log service_json;
}

Case:
1) Make curl "127.0.0.1/test/?return=200"
backend response 200 ok
nginx response 200 ok AND $upstream_cache_status=MISS

2) Make curl "127.0.0.1/test/?return=200"
backend response -
nginx response 200 ok AND $upstream_cache_status=HIT

3) Wait until cache expired

4) Make curl "127.0.0.1/test/?return=302"
nginx response 200 ok AND $upstream_cache_status=STALE
backend respose 302 moved temporarily

5) Make curl "127.0.0.1/test/?return=302"
nginx response 200 ok AND $upstream_cache_status=STALE
backend respose 302 moved temporarily

6) Make curl "127.0.0.1/test/?return=301"
nginx response 200 ok AND $upstream_cache_status=STALE
backend respose 301 moved permanently

7) Make curl "127.0.0.1/test/?return=301"
nginx response 301 moved permanently AND $upstream_cache_status=HIT
backend respose -

So, if fastcgi_cache_background_update is on, cache expired and background response of upstream does not match with caching rules cache never invalidate.

Attachments (1)

access.log (9.9 KB ) - added by artemsuv@… 7 years ago.
access.log

Download all attachments as: .zip

Change History (1)

by artemsuv@…, 7 years ago

Attachment: access.log added

access.log

Note: See TracTickets for help on using tickets.