Opened 12 years ago

Closed 12 years ago

#130 closed defect (invalid)

proxy_cache_lock does not work as expected

Reported by: openid.yandex.ru/pixelbender Owned by: somebody
Priority: minor Milestone:
Component: nginx-module Version: 1.1.x
Keywords: proxy cache lock proxy_cache_lock Cc:
uname -a: Linux virtualbox 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux
nginx -V:
nginx version: nginx/1.1.14
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd-nginx_1.1.14-1~bpo60+1-i386-SwftRi/nginx-1.1.14/debian/modules/nginx-echo --add-module=/build/buildd-nginx_1.1.14-1~bpo60+1-i386-SwftRi/nginx-1.1.14/debian/modules/nginx-upstream-fair

Description

The Problem
===========

Seems proxy_cache_lock does not work as expected

File: default
=============

server {

listen 80;
location / {

proxy_pass http://localhost:8080/index.php;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_cache_valid 5s;
proxy_cache cache;
proxy_ignore_client_abort on;
proxy_cache_key $request_uri$host;
proxy_cache_lock on;
proxy_cache_lock_timeout 10m;

}

}

File: index.php
===============

<?php
usleep(rand(10000, 20000));
echo rand(0,1000000000);
?>

Output
======

Different results: 1 (+101061301)
Different results: 2 (+657023466)
Different results: 3 (+499714216)
Different results: 4 (+277901683)
Different results: 5 (+317902436)
Different results: 6 (+896635636)
Different results: 7 (+463205066)
Different results: 8 (+753108359)
Different results: 9 (+656662217)
Different results: 10 (+350354652)
Different results: 11 (+428192035)
Different results: 12 (+382234339)
Different results: 13 (+735190009)
Different results: 14 (+124753595)
Different results: 15 (+156651065)
Different results: 16 (+468289203)
Different results: 17 (+131853834)
Different results: 18 (+107945026)
Different results: 19 (+66802585)
Different results: 20 (+112003177)
Different results: 21 (+216053443)
Different results: 22 (+900513314)
Different results: 23 (+653193969)
Different results: 24 (+325815718)
...
(execution time is less than 1 second)

Expected output
===============

Different results: 1 (+101061301)
Different results: 2 (+657023466)
(1 or 2 output lines)

Attachments (1)

NginxTester.java (1.8 KB ) - added by openid.yandex.ru/pixelbender 12 years ago.
Test (Java)

Download all attachments as: .zip

Change History (6)

by openid.yandex.ru/pixelbender, 12 years ago

Attachment: NginxTester.java added

Test (Java)

comment:1 by Maxim Dounin, 12 years ago

Output suggests cache doesn't work at all. Most likely culprit is php which auto-start sessions and returns Set-Cookie, which in turn disables caching in nginx. Try looking into response headers returned. To use cache regardless of Set-Cookie you may use "proxy_ignore_headers Set-Cookie".

comment:2 by openid.yandex.ru/pixelbender, 12 years ago

The cache does work. I have got expected results running one thread of testing process.

comment:3 by Maxim Dounin, 12 years ago

Please provide debug log, see http://nginx.org/en/docs/debugging_log.html.

comment:5 by Maxim Dounin, 12 years ago

Resolution: invalid
Status: newclosed

You have stale cached response in cache, and this prevents proxy_cache_lock from working (as it doesn't handle updating process, only adding new items). To handle updating, use proxy_cache_use_stale updating;.

Note: See TracTickets for help on using tickets.