Hello!
Thanks for your report!
I tried your test case on my side (though I had to fix a typo in your
Lua code and also add more stuff to make it runnable) and cannot
reproduce the problem using the same openresty version on x86_64
Linux. Below is my test case using OpenResty's test scaffold
Test::Nginx::Socket::Lua (this way, everyone can easily run it on
their side):
use Test::Nginx::Socket::Lua 'no_plan';
repeat_each(300);
run_tests;
__DATA__
=== TEST 1: test case from community
--- http_config
upstream self {
server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
balancer_by_lua_block {
local t = ngx.ctx.t
for key, value in pairs(t) do print(key) end -- output is empty
for key, value in pairs(t) do print(key) end -- have output
}
}
--- config
location = /t {
rewrite_by_lua_block {
local t = {["1.2.3.4"] = { ["weight"] = 1}, ["4.5.6.7"] =
{ ["weight"] = 2}}
ngx.ctx.t = t
}
proxy_pass
http://self/;
}
--- request
GET /t
--- response_body_like chop
It works
--- error_log
4.5.6.7
1.2.3.4
--- ONLY
I added repeat_each(300); near the beginning of the .t test file so
that it can trigger LuaJIT's JIT compiling. And all the test runs were
completed successfully. And to count the output lines in the nginx
error.log file:
$ grep '4.5.6.7 while connecting to upstream' t/servroot/logs/error.log|wc -l
600
$ grep '1.2.3.4 while connecting to upstream' t/servroot/logs/error.log|wc -l
600
We can see that we didn't miss a single line of key output. It is
indeed 2 * 300 == 600 lines for each key value.
I also tried commenting out the 2nd "for" loop statement on my side
and this time it still produces the expected output, just half of the
key values are printed in the error.log file:
$ grep '4.5.6.7 while connecting to upstream' t/servroot/logs/error.log|wc -l
300
$ grep '1.2.3.4 while connecting to upstream' t/servroot/logs/error.log|wc -l
300
Will you prepare a minimal and standalone example that can help us
reproduce the problem on our side? Or am I missing something here?
Thanks!
Best,
Yichun