Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: missing clear table before to reuse table. #1134

Merged
merged 5 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lua/apisix/core/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ local error = error
local select = select
local type = type
local ngx_exit = ngx.exit
local insert_tab = table.insert
local concat_tab = table.concat
local str_sub = string.sub
local tonumber = tonumber
local clear_tab = require("table.clear")
local pairs = pairs

local _M = {version = 0.1}
Expand All @@ -37,10 +37,12 @@ do
local idx = 1

function resp_exit(code, ...)
clear_tab(t)
idx = 0

if code and type(code) ~= "number" then
insert_tab(t, code)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always insert new data and then memory leak.

idx = idx + 1
t[idx] = code
code = nil
end

Expand All @@ -56,12 +58,12 @@ function resp_exit(code, ...)
error("failed to encode data: " .. err, -2)
else
idx = idx + 1
insert_tab(t, idx, body .. "\n")
t[idx] = body .. "\n"
end

elseif v ~= nil then
idx = idx + 1
insert_tab(t, idx, v)
t[idx] = v
end
end

Expand Down
31 changes: 19 additions & 12 deletions t/admin/routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ passed
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local core = require("apisix.core")
moonming marked this conversation as resolved.
Show resolved Hide resolved
-- set
local code, body, res = t('/apisix/admin/routes/1?ttl=1',
ngx.HTTP_PUT,
Expand All @@ -1383,7 +1384,7 @@ location /t {
}]]
)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.say("code: ", code)
ngx.say(body)

-- get
Expand All @@ -1400,24 +1401,27 @@ location /t {
}]]
)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.say("code: ", code)
ngx.say(body)

ngx.sleep(2)

-- get again
code, body, res = t('/apisix/admin/routes/1', ngx.HTTP_GET)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.print(body)
ngx.say("code: ", code)
ngx.say("message: ", core.json.decode(body).message)
}
}
--- request
GET /t
--- response_body_like eval
qr$passed
--- response_body
code: 200
passed
code: 200
passed
code: 404 {"cause":"\\/apisix\\/routes\\/1","index":\d+,"errorCode":100,"message":"Key not found"}$
code: 404
message: Key not found
--- no_error_log
[error]
--- timeout: 5
Expand All @@ -1429,6 +1433,8 @@ code: 404 {"cause":"\\/apisix\\/routes\\/1","index":\d+,"errorCode":100,"message
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local core = require("apisix.core")

local code, body, res = t('/apisix/admin/routes?ttl=1',
ngx.HTTP_POST,
[[{
Expand Down Expand Up @@ -1456,15 +1462,16 @@ location /t {
local id = string.sub(res.node.key, #"/apisix/routes/" + 1)
code, body = t('/apisix/admin/routes/' .. id, ngx.HTTP_GET)

if code >= 300 then ngx.print("code: ", code, " ") end
ngx.print(body)
ngx.say("code: ", code)
ngx.say("message: ", core.json.decode(body).message)
}
}
--- request
GET /t
--- response_body_like eval
qr$succ: passed
code: 404 {"cause":"\\/apisix\\/routes\\/\d+","index":\d+,"errorCode":100,"message":"Key not found"}$
--- response_body
[push] succ: passed
code: 404
message: Key not found
--- no_error_log
[error]
--- timeout: 5
Expand Down
1 change: 0 additions & 1 deletion utils/check-lua-code-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ luacheck -q lua
lua/apisix/plugins/limit-count/*.lua > \
/tmp/check.log 2>&1 || (cat /tmp/check.log && exit 1)

sed -i 's/.*newproxy.*//g' /tmp/check.log
count=`grep -E ".lua:[0-9]+:" /tmp/check.log -c || true`

if [ $count -ne 0 ]
Expand Down