Permalink
Browse files

fixed the zero size buf alert in error.log when $memc_value is set to…

… empty (). thanks iframist.
  • Loading branch information...
1 parent 835c9c4 commit 55c2852ca545978a293a348fcb61eee47743eaf2 @agentzh agentzh committed Oct 28, 2010
Showing with 37 additions and 152 deletions.
  1. +18 −16 src/ngx_http_memc_request.c
  2. +0 −135 test/t/bug.t
  3. +19 −1 test/t/stats.t
@@ -177,28 +177,30 @@ ngx_http_memc_create_storage_cmd_request(ngx_http_request_t *r)
*b->last++ = CR; *b->last++ = LF;
if (memc_value_vv) {
- dd("copy $memc_value to the request");
- b = ngx_calloc_buf(r->pool);
+ if (memc_value_vv->len) {
+ dd("copy $memc_value to the request");
+ b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
- b->memory = 1;
+ b->memory = 1;
- b->start = b->pos = memc_value_vv->data;
- b->last = b->end = b->start + memc_value_vv->len;
+ b->start = b->pos = memc_value_vv->data;
+ b->last = b->end = b->start + memc_value_vv->len;
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
- cl->buf = b;
- cl->next = NULL;
+ cl->buf = b;
+ cl->next = NULL;
- *ll = cl;
- ll = &cl->next;
+ *ll = cl;
+ ll = &cl->next;
+ }
} else {
/* to preserve the r->request_body->bufs untouched */
View
@@ -1,135 +0,0 @@
-# vi:filetype=perl
-
-use lib 'lib';
-use Test::Nginx::Socket;
-
-plan tests => repeat_each() * 2 * blocks();
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff;
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: set only
---- http_config
- upstream mc {
- server 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
---- config
- location = "/set" {
- set $memc_cmd 'set';
- set $memc_key 'jalla';
- set $memc_value 'myvalue';
- set $memc_exptime 24;
- memc_pass mc;
- }
-
-
- location = "/get" {
- set $memc_cmd 'get';
- set $memc_key 'jalla';
- memc_pass mc;
- }
-
- location = "/delete" {
- set $memc_cmd 'delete';
- set $memc_key 'jalla';
- memc_pass mc;
- }
- location = "/flush" {
- echo_location /get;
- #echo "";
- echo_location /delete;
- }
---- request
- GET /flush
---- response_body eval
-"STORED\r\n"
---- error_code: 201
---- SKIP
-
-
-
-=== TEST 2: set in a subrequest issued from an output filter
---- config
- location /memc {
- set $memc_cmd 'set';
- set $memc_key 'foo';
- set $memc_value 'blah';
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
- location /main {
- default_type 'text/html';
- add_before_body '/memc';
- echo '~~';
- add_after_body '/memc';
- }
---- request
-GET /main
---- response_body eval
-"STORED\r
-~~
-STORED\r
-"
-
-
-=== TEST 19: reuse request body
---- config
- location /main {
- echo_read_request_body;
-
- echo 'flush_all';
- echo_location '/memc?cmd=flush_all';
-
- echo 'set foo';
- echo_subrequest POST '/memc?key=foo&cmd=set';
-
- echo 'set bar';
- echo_subrequest POST '/memc?key=bar&cmd=set';
-
- echo 'get bar';
- echo_location '/memc?key=bar&cmd=get';
-
- echo 'get foo';
- echo_location '/memc?key=foo&cmd=get';
- }
- location /memc {
- echo_before_body "status: $echo_response_status";
- echo_before_body "exptime: $memc_exptime";
-
- set $memc_cmd $arg_cmd;
- set $memc_key $arg_key;
- #set $memc_value $arg_val;
- set $memc_exptime $arg_exptime;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
-POST /main
-Hello
---- response_body eval
-"flush_all
-status: 200
-exptime:
-OK\r
-set foo
-status: 201
-exptime: 0
-STORED\r
-set bar
-status: 201
-exptime: 0
-STORED\r
-get bar
-status: 200
-exptime:
-Helloget foo
-status: 200
-exptime:
-Hello"
-
View
@@ -1,13 +1,16 @@
# vi:filetype=perl
use lib 'lib';
-use Test::Nginx::LWP;
+use Test::Nginx::Socket;
+
+repeat_each(1);
plan tests => repeat_each() * 2 * blocks();
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
#no_diff;
+log_level('error');
run_tests();
@@ -23,3 +26,18 @@ __DATA__
GET /stats
--- response_body_like: ^(?:STAT [^\r]*\r\n)*END\r\n$
+
+=== TEST 1: timeout
+--- config
+ memc_connect_timeout 10ms;
+ memc_send_timeout 10ms;
+ location /stats {
+ set $memc_cmd stats;
+ memc_pass www.taobao.com:12345;
+ }
+--- request
+ GET /stats
+--- response_body_like: 504 Gateway Time-out
+--- timeout: 1
+--- error_code: 504
+

0 comments on commit 55c2852

Please sign in to comment.