Skip to content

Commit a162b7f

Browse files
committed
bugfix: this module might not work properly with multiple http {} blocks in nginx.conf.
1 parent 78b0d54 commit a162b7f

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed

src/ngx_http_srcache_filter_module.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ ngx_http_srcache_store_statuses(ngx_conf_t *cf, ngx_command_t *cmd,
3333
void *conf);
3434

3535

36+
static volatile ngx_cycle_t *ngx_http_srcache_prev_cycle = NULL;
37+
38+
3639
static ngx_str_t ngx_http_srcache_hide_headers[] = {
3740
ngx_string("Connection"),
3841
ngx_string("Keep-Alive"),
@@ -505,6 +508,7 @@ ngx_http_srcache_init_main_conf(ngx_conf_t *cf, void *conf)
505508
static ngx_int_t
506509
ngx_http_srcache_post_config(ngx_conf_t *cf)
507510
{
511+
int multi_http_blocks;
508512
ngx_int_t rc;
509513
ngx_http_handler_pt *h;
510514
ngx_http_core_main_conf_t *cmcf;
@@ -518,7 +522,15 @@ ngx_http_srcache_post_config(ngx_conf_t *cf)
518522
smcf = ngx_http_conf_get_module_main_conf(cf,
519523
ngx_http_srcache_filter_module);
520524

521-
if (smcf->module_used) {
525+
if (ngx_http_srcache_prev_cycle != ngx_cycle) {
526+
ngx_http_srcache_prev_cycle = ngx_cycle;
527+
multi_http_blocks = 0;
528+
529+
} else {
530+
multi_http_blocks = 1;
531+
}
532+
533+
if (multi_http_blocks || smcf->module_used) {
522534

523535
dd("using ngx-srcache");
524536

t/unused.t

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# vi:filetype=
2+
3+
use lib 'lib';
4+
use Test::Nginx::Socket;
5+
6+
#repeat_each(2);
7+
8+
plan tests => repeat_each() * (3 * blocks());
9+
10+
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
11+
12+
#master_on();
13+
no_long_string();
14+
no_shuffle();
15+
16+
run_tests();
17+
18+
__DATA__
19+
20+
=== TEST 1: module used
21+
--- config
22+
location /foo {
23+
srcache_store PUT /store;
24+
echo hello;
25+
}
26+
27+
location /store {
28+
echo stored;
29+
}
30+
--- request
31+
GET /foo
32+
--- stap
33+
F(ngx_http_srcache_header_filter) {
34+
println("srcache header filter called")
35+
}
36+
37+
F(ngx_http_srcache_access_handler) {
38+
println("srcache access handler called")
39+
}
40+
41+
--- stap_out
42+
srcache access handler called
43+
srcache access handler called
44+
srcache header filter called
45+
srcache header filter called
46+
--- response_body
47+
hello
48+
49+
50+
51+
=== TEST 2: module unused
52+
--- config
53+
location /foo {
54+
#srcache_store PUT /store;
55+
echo hello;
56+
}
57+
58+
location /store {
59+
echo stored;
60+
}
61+
--- request
62+
GET /foo
63+
--- stap
64+
F(ngx_http_srcache_header_filter) {
65+
println("srcache header filter called")
66+
}
67+
68+
F(ngx_http_srcache_access_handler) {
69+
println("srcache access handler called")
70+
}
71+
72+
--- stap_out
73+
--- response_body
74+
hello
75+
76+
77+
78+
=== TEST 3: module used (multiple http {} blocks)
79+
--- config
80+
location /foo {
81+
srcache_store PUT /store;
82+
echo hello;
83+
}
84+
85+
location /store {
86+
echo stored;
87+
}
88+
89+
--- post_main_config
90+
http {
91+
}
92+
93+
--- request
94+
GET /foo
95+
--- stap
96+
F(ngx_http_srcache_header_filter) {
97+
println("srcache header filter called")
98+
}
99+
100+
F(ngx_http_srcache_access_handler) {
101+
println("srcache access handler called")
102+
}
103+
104+
--- stap_out
105+
srcache access handler called
106+
srcache access handler called
107+
srcache header filter called
108+
srcache header filter called
109+
--- response_body
110+
hello
111+

0 commit comments

Comments
 (0)