This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 972840e fix: skip tombstone mark when iterating the global values
(#1517)
972840e is described below
commit 972840ec965e291ade089a93acfc2f065a0a0554
Author: 罗泽轩 <[email protected]>
AuthorDate: Tue Apr 28 17:25:55 2020 +0800
fix: skip tombstone mark when iterating the global values (#1517)
Close #1473.
---
apisix/core/config_util.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++
apisix/init.lua | 8 +++++---
t/node/global-rule.t | 7 +++++++
3 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/apisix/core/config_util.lua b/apisix/core/config_util.lua
new file mode 100644
index 0000000..1e39921
--- /dev/null
+++ b/apisix/core/config_util.lua
@@ -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
diff --git a/apisix/init.lua b/apisix/init.lua
index aa8598e..48c5b80 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -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")
@@ -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
@@ -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
@@ -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)
diff --git a/t/node/global-rule.t b/t/node/global-rule.t
index c1de5dd..a31a013 100644
--- a/t/node/global-rule.t
+++ b/t/node/global-rule.t
@@ -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]