Skip to content

Commit 05bc2cb

Browse files
committed
feature: log an error message when srcache_store subrequest has an error or returns a bad http status code. thanks Yann Coleu for the report.
1 parent b2b8dda commit 05bc2cb

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

src/ngx_http_srcache_store.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,15 @@ static ngx_int_t
644644
ngx_http_srcache_store_post_subrequest(ngx_http_request_t *r, void *data,
645645
ngx_int_t rc)
646646
{
647+
if (rc == NGX_ERROR
648+
|| rc >= NGX_HTTP_SPECIAL_RESPONSE
649+
|| r->headers_out.status >= NGX_HTTP_SPECIAL_RESPONSE)
650+
{
651+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
652+
"srcache_store subrequest failed: rc=%i status=%ui",
653+
rc, r->headers_out.status);
654+
}
655+
647656
return NGX_OK;
648657
}
649658

t/bugs.t

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ finalize: 0
547547
Content-Type: text/css
548548
--- response_body
549549
I do like you
550-
--- no_error_log
551-
[error]
550+
--- error_log
551+
srcache_store subrequest failed: rc=-1 status=0
552552
553553
554554
@@ -600,8 +600,8 @@ finalize: 0
600600
Content-Type: text/css
601601
--- response_body
602602
I do like you
603-
--- no_error_log
604-
[error]
603+
--- error_log
604+
srcache_store subrequest failed: rc=500 status=0,
605605
606606
607607
@@ -629,3 +629,41 @@ srcache_fetch: cache sent truncated response body
629629
--- no_error_log
630630
[alert]
631631
632+
633+
634+
=== TEST 18: store subrequest failure
635+
--- http_config
636+
upstream local {
637+
server localhost:$TEST_NGINX_MEMCACHED_PORT;
638+
}
639+
640+
--- config
641+
memc_connect_timeout 100ms;
642+
memc_send_timeout 100ms;
643+
memc_read_timeout 100ms;
644+
645+
location = /memc {
646+
internal;
647+
648+
set $memc_key $query_string;
649+
set $memc_exptime 1d;
650+
memc_pass local;
651+
}
652+
653+
location = /tblah {
654+
srcache_fetch GET /memc $uri;
655+
srcache_store PUT /memc $uri;
656+
proxy_pass http://127.0.0.1:$server_port/back;
657+
}
658+
659+
location = /back {
660+
echo ok;
661+
}
662+
--- request
663+
GET /tblah
664+
--- response_body
665+
ok
666+
--- error_log
667+
variable "$memc_exptime" takes invalid value: 1d,
668+
srcache_store subrequest failed: rc=400 status=0,
669+

0 commit comments

Comments
 (0)