openresty / memc-nginx-module

An extended version of the standard memcached module that supports set, add, delete, and many more memcached commands.
http://wiki.nginx.org/NginxHttpMemcModule
213 stars 56 forks source link

nginx-1.5.3 changed u->length default #11

Closed maage closed 11 years ago

maage commented 11 years ago

./configure --add-module=agentzh-echo-nginx-module-4de92b1 --add-module=agentzh-memc-nginx-module-6081fe5 --with-http_addition_module --with-debug

nginx version: nginx/1.5.4 built by gcc 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC) configure arguments: --add-module=agentzh-echo-nginx-module-4de92b1 --add-module=agentzh-memc-nginx-module-6081fe5 --with-http_addition_module --with-debug

There seems to be some kind of error. Seen on many tests. But first to see it is bugs.t TEST 3

Run test:

TEST_NGINX_BINARY=../objs/nginx prove -r t/bugs.t

Output, (three times actually).

t/bugs.t .. 7/36 
#   Failed test 'TEST 3: reuse request body - no last chunk found - a
# flush_all
#
# c
# status: 200
#
# a
# exptime:
#
#4
# OK
#
#8
# set foo
#
# c
# status: 201
#
# b
# exptime: 0
#
#8
# STORED
#
#8
# set bar
#
# c
# status: 201
#
# b
# exptime: 0
#
#8
# STORED
#
# '
#   at /usr/local/share/perl5/Test/Nginx/Socket.pm line 1214.

#   Failed test 'TEST 3: reuse request body - status code ok'
#   at /usr/local/share/perl5/Test/Nginx/Socket.pm line 788.
#          got: ''
#     expected: '200'

#   Failed test 'TEST 3: reuse request body - response_body - response is expected'
#   at /usr/local/share/perl5/Test/Nginx/Socket.pm line 1076.
#          got: undef
#     expected: 'flush_all
# status: 200
# exptime:
# OK
# set foo
# status: 201
# exptime: 0
# STORED
# set bar
# status: 201
# exptime: 0
# STORED
# get bar
# status: 200
# exptime:
# Helloget foo
# status: 200
# exptime:
# Hello'
WARNING: TEST 3: reuse request body - 2013/08/30 17:56:12 [alert] 29553#0: *1 writev() failed (22: Invalid argument) while sending to client, client: 127.0.0.1, server: localhost, request: \"POST /main HTTP/1.1\", subrequest: \"/memc\", upstream: \"memcached://127.0.0.1:11211\", host: \"localhost\" at /usr/local/share/perl5/Test/Nginx/Socket.pm line 1002.
WARNING: TEST 3: reuse request body - 2013/08/30 17:56:12 [alert] 29553#0: *6 writev() failed (22: Invalid argument) while sending to client, client: 127.0.0.1, server: localhost, request: \"POST /main HTTP/1.1\", subrequest: \"/memc\", upstream: \"memcached://127.0.0.1:11211\", host: \"localhost\" at /usr/local/share/perl5/Test/Nginx/Socket.pm line 1002.
WARNING: TEST 3: reuse request body - 2013/08/30 17:56:12 [alert] 29553#0: *11 writev() failed (22: Invalid argument) while sending to client, client: 127.0.0.1, server: localhost, request: \"POST /main HTTP/1.1\", subrequest: \"/memc\", upstream: \"memcached://127.0.0.1:11211\", host: \"localhost\" at /usr/local/share/perl5/Test/Nginx/Socket.pm line 1002.

I bisected and nginx commit to break is:

commit 416b922bd2c285551d195c1f33a3736775ea45e9
Author: Maxim Dounin <mdounin@mdounin.ru>
Date:   Thu Jul 25 14:58:11 2013 +0400

    Upstream: u->length now defaults to -1 (API change).

    That is, by default we assume that response end is signalled by
    a connection close.  This seems to be better default, and in line
    with u->pipe->length behaviour.

    Memcached module was modified accordingly.

Fix:

diff --git a/src/ngx_http_memc_response.rl b/src/ngx_http_memc_response.rl
index 83d1b4a..fdf52e4 100644
--- a/src/ngx_http_memc_response.rl
+++ b/src/ngx_http_memc_response.rl
@@ -274,7 +274,11 @@ ngx_http_memc_get_cmd_filter_init(void *data)

     dd("filter init: u->length: %d", (int) u->length);

+#if defined(nginx_version) && nginx_version >= 1005003
+    u->length = u->headers_in.content_length_n + NGX_HTTP_MEMC_END;
+#else
     u->length += NGX_HTTP_MEMC_END;
+#endif

     dd("filter init (2): u->length: %d", (int) u->length);
agentzh commented 11 years ago

I've applied a slightly modified version of your patch to master. Please try it out :) Thank you for your contribution!

maage commented 11 years ago

Now my test suite passes. Thank you.