Skip to content

Commit 159d276

Browse files
committed
bugfix: use of C global variables at the configuration phase would cause troubles when HUP reload failed.
1 parent 4010205 commit 159d276

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

src/ngx_http_srcache_filter_module.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
unsigned ngx_http_srcache_used;
2222

2323

24-
static ngx_int_t ngx_http_srcache_pre_config(ngx_conf_t *cf);
2524
static void *ngx_http_srcache_create_loc_conf(ngx_conf_t *cf);
2625
static char *ngx_http_srcache_merge_loc_conf(ngx_conf_t *cf, void *parent,
2726
void *child);
@@ -211,7 +210,7 @@ static ngx_command_t ngx_http_srcache_commands[] = {
211210

212211

213212
static ngx_http_module_t ngx_http_srcache_filter_module_ctx = {
214-
ngx_http_srcache_pre_config, /* preconfiguration */
213+
NULL, /* preconfiguration */
215214
ngx_http_srcache_post_config, /* postconfiguration */
216215

217216
ngx_http_srcache_create_main_conf, /* create main configuration */
@@ -241,17 +240,6 @@ ngx_module_t ngx_http_srcache_filter_module = {
241240
};
242241

243242

244-
static ngx_int_t
245-
ngx_http_srcache_pre_config(ngx_conf_t *cf)
246-
{
247-
#if 1
248-
ngx_http_srcache_used = 0;
249-
#endif
250-
251-
return NGX_OK;
252-
}
253-
254-
255243
static void *
256244
ngx_http_srcache_create_loc_conf(ngx_conf_t *cf)
257245
{
@@ -374,14 +362,18 @@ ngx_http_srcache_conf_set_request(ngx_conf_t *cf, ngx_command_t *cmd,
374362
ngx_str_t *value;
375363
ngx_str_t *method_name;
376364
ngx_http_compile_complex_value_t ccv;
365+
ngx_http_srcache_main_conf_t *smcf;
377366

378367
rpp = (ngx_http_srcache_request_t **) (p + cmd->offset);
379368

380369
if (*rpp != NGX_CONF_UNSET_PTR) {
381370
return "is duplicate";
382371
}
383372

384-
ngx_http_srcache_used = 1;
373+
smcf = ngx_http_conf_get_module_main_conf(cf,
374+
ngx_http_srcache_filter_module);
375+
376+
smcf->module_used = 1;
385377

386378
value = cf->args->elts;
387379

@@ -460,6 +452,7 @@ ngx_http_srcache_create_main_conf(ngx_conf_t *cf)
460452

461453
/* set by ngx_pcalloc:
462454
* smcf->postponed_to_access_phase_end = 0;
455+
* smcf->module_used = 0;
463456
* smcf->headers_in_hash = { NULL, 0 };
464457
*/
465458

@@ -518,13 +511,17 @@ ngx_http_srcache_post_config(ngx_conf_t *cf)
518511
ngx_int_t rc;
519512
ngx_http_handler_pt *h;
520513
ngx_http_core_main_conf_t *cmcf;
514+
ngx_http_srcache_main_conf_t *smcf;
521515

522516
rc = ngx_http_srcache_add_variables(cf);
523517
if (rc != NGX_OK) {
524518
return rc;
525519
}
526520

527-
if (ngx_http_srcache_used) {
521+
smcf = ngx_http_conf_get_module_main_conf(cf,
522+
ngx_http_srcache_filter_module);
523+
524+
if (smcf->module_used) {
528525

529526
dd("using ngx-srcache");
530527

src/ngx_http_srcache_filter_module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ typedef struct {
8787

8888
typedef struct {
8989
unsigned postponed_to_access_phase_end;
90+
unsigned module_used;
9091
ngx_hash_t headers_in_hash;
9192

9293
} ngx_http_srcache_main_conf_t;

t/main-req.t

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test::Nginx::Socket;
55

66
#repeat_each(2);
77

8-
plan tests => repeat_each() * (5 * blocks() + 4);
8+
plan tests => repeat_each() * (5 * blocks() + 5);
99

1010
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
1111

@@ -16,7 +16,7 @@ run_tests();
1616

1717
__DATA__
1818
19-
=== TEST 1: flush all
19+
=== TEST 1: flush all (not using ngx_srcache)
2020
--- config
2121
location /flush {
2222
set $memc_cmd 'flush_all';
@@ -29,6 +29,21 @@ Content-Type: text/plain
2929
Content-Length: 4
3030
X-Fetch-Status: BYPASS
3131
X-Store-Status: BYPASS
32+
33+
--- stap
34+
F(ngx_http_srcache_access_handler) {
35+
println("srcache access handler")
36+
}
37+
38+
F(ngx_http_srcache_header_filter) {
39+
println("srcache header filter")
40+
}
41+
42+
F(ngx_http_srcache_body_filter) {
43+
println("srcache body filter")
44+
}
45+
46+
--- stap_out
3247
--- request
3348
GET /flush
3449
--- response_body eval: "OK\r\n"

0 commit comments

Comments
 (0)