Skip to content

Commit

Permalink
fix: skip tombstone mark when iterating the global values (apache#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored and SaberMaster committed Jun 30, 2020
1 parent 798cf9f commit f42d99a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
45 changes: 45 additions & 0 deletions apisix/core/config_util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local setmetatable = setmetatable
local type = type


local _M = {}


local function _iterate_values(self, tab)
while true do
self.idx = self.idx + 1
local v = tab[self.idx]
if type(v) == "table" then
return self.idx, v
end
if v == nil then
return nil, nil
end
-- skip the tombstone
end
end


function _M.iterate_values(tab)
local iter = setmetatable({idx = 0}, {__call = _iterate_values})
return iter, tab, 0
end


return _M
8 changes: 5 additions & 3 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
--
local require = require
local core = require("apisix.core")
local config_util = require("apisix.core.config_util")
local plugin = require("apisix.plugin")
local service_fetch = require("apisix.http.service").get
local admin_init = require("apisix.admin.init")
Expand All @@ -27,7 +28,6 @@ local get_method = ngx.req.get_method
local ngx_exit = ngx.exit
local math = math
local error = error
local ipairs = ipairs
local pairs = pairs
local tostring = tostring
local load_balancer
Expand Down Expand Up @@ -263,7 +263,8 @@ function _M.http_access_phase()
if router.global_rules and router.global_rules.values
and #router.global_rules.values > 0 then
local plugins = core.tablepool.fetch("plugins", 32, 0)
for _, global_rule in ipairs(router.global_rules.values) do
local values = router.global_rules.values
for _, global_rule in config_util.iterate_values(values) do
api_ctx.conf_type = "global_rule"
api_ctx.conf_version = global_rule.modifiedIndex
api_ctx.conf_id = global_rule.value.id
Expand Down Expand Up @@ -451,7 +452,8 @@ local function common_phase(plugin_name)
and #router.global_rules.values > 0
then
local plugins = core.tablepool.fetch("plugins", 32, 0)
for _, global_rule in ipairs(router.global_rules.values) do
local values = router.global_rules.values
for _, global_rule in config_util.iterate_values(values) do
core.table.clear(plugins)
plugins = plugin.filter(global_rule, plugins)
run_plugin(plugin_name, plugins, api_ctx)
Expand Down
7 changes: 7 additions & 0 deletions t/node/global-rule.t
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,18 @@ GET /hello
ngx.status = code
end
ngx.say(body)
local code, body = t('/not_found', ngx.HTTP_GET)
ngx.say(code)
local code, body = t('/not_found', ngx.HTTP_GET)
ngx.say(code)
}
}
--- request
GET /t
--- response_body
passed
404
404
--- no_error_log
[error]

0 comments on commit f42d99a

Please sign in to comment.