Nginx-LuaJIT core

Sirsiwal, Umesh usirsiwal at
Wed May 18 07:15:47 MSD 2011

Thank agentzh,
The original code was trying to correctly send the error code in presence of error returned by upstream. 

I ran my nginx under valgrind today. Periodically I get the following. This is probably something in luajit but I wanted to report this here before I report it to luajit list.

==21286== Conditional jump or move depends on uninitialised value(s)
==21286==    at 0x5788D2E: lj_str_new (lj_str.c:66)
==21286==    by 0x578E014: lua_pushlstring (lj_api.c:581)
==21286==    by 0x498291: ngx_http_lua_var_get (ngx_http_lua_util.c:711)
==21286==    by 0x5783718: lj_BC_FUNCC (in /usr/local/lib/
==21286==    by 0x49872D: ngx_http_lua_run_thread (ngx_http_lua_util.c:997)
==21286==    by 0x49B267: ngx_http_lua_access_by_chunk (ngx_http_lua_accessby.c:78)
==21286==    by 0x49B464: ngx_http_lua_access_handler_file (ngx_http_lua_accessby.c:128)
==21286==    by 0x49B0F2: ngx_http_lua_access_handler (ngx_http_lua_accessby.c:250)
==21286==    by 0x457FDC: ngx_http_core_access_phase (ngx_http_core_module.c:1060)
==21286==    by 0x4541D2: ngx_http_core_run_phases (ngx_http_core_module.c:837)
==21286==    by 0x4542CF: ngx_http_handler (ngx_http_core_module.c:820)
==21286==    by 0x45E59B: ngx_http_process_request (ngx_http_request.c:1671)

From: agentzh [agentzh at]
Sent: Wednesday, May 11, 2011 12:20 AM
To: Sirsiwal, Umesh
Cc: nginx-devel at
Subject: Re: Nginx-LuaJIT core

On Wed, May 11, 2011 at 6:18 AM, Umesh Sirsiwal <usirsiwal at> wrote:
> I have not yet run the nginx with valgrind. However, changing the original
> lua file to the following fixes the issue. It turns out the output can be
> 100MB+. I will keep digging.
> local prox = 3201
> local nrAgent = 8
> ngx.print("coblitzstat\n")
> for p = prox, prox+nrAgent-1 do
>        local l = "/prox" .. p .. ngx.var['request_uri']
>        print("copass: fetching location " .. l)
>        local res = ngx.location.capture(l)
>        if (res.status ~= ngx.HTTP_OK and res.status ~= 504) then
>          return(res.status)
>        end
>        if(res.status == ngx.HTTP_OK and string.len(res.body)>  0) then
>          ngx.print(res.body)
>        end
> end

Just a side note: calling ngx.print() right after
ngx.location.capture() in your loop is strongly recommended because
for HTTP 1.1 requests, the upstream and downstream (non-blocking)
network I/O can be overlapped very well in this scenario, thus
increasing the overall throughput, reducing response latency, and
decreasing memory use on the server side :)

For HTTP 1.0 requests, where ngx_lua will automatically buffer all the
outputs on the C level in order to obtain the response length and make
up a proper Content-Length header for the HTTP 1.0 response.

Thank you for digging into this issue ;)


More information about the nginx-devel mailing list