bug in ngx_http_upstream_process_body_in_memory
|Reported by:||Eran Kornblau||Owned by:|
|Keywords:||upstream buffer input_filter||Cc:|
|uname -a:||Linux pa-nginx-vod-stg1 3.5.0-41-generic #64~precise1-Ubuntu SMP Thu Sep 12 16:50:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux|
nginx version: nginx/1.6.0
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configure arguments: --add-module=/opt/nginx-vod-module/ --add-module=/usr/local/src/nginx_mod_akamai_g2o/ --with-http_stub_status_module --with-file-aio --conf-path=/opt/nginx-vod-module-saas/conf/nginx.conf
I believe that in ngx_http_upstream_process_body_in_memory the for (;;) loop should be replaced with while (u->length).
In the module I'm working on, I know in advance the exact size of upstream response (since I'm issuing an HTTP range request) and I manipulate the upstream buffer to point to my buffer in order to avoid memory copy operations.
When my custom u->input_filter returns, u->length is 0, which should indicate that the response arrived in full. However, since the buffer is in the exact size, the code enters if (size == 0) and the upstream request is completed with NGX_ERROR.
I can probably work around this by passing a slightly larger buffer, but that means another call to recv will be made for no reason.