You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "caobaorui (via GitHub)" <gi...@apache.org> on 2023/05/24 03:18:12 UTC
[GitHub] [apisix] caobaorui opened a new issue, #9533: bug: Is there any concurrency problem in the execution of the plug-in? The id of the route obtained earlier is changed after being passed to a method for use
caobaorui opened a new issue, #9533:
URL: https://github.com/apache/apisix/issues/9533
### Current Behavior
Is there any concurrency problem in the execution of the plug-in? The id of the route obtained earlier is changed after being passed to a method for use
### Expected Behavior
`--通过路由id,远程调用http接口更新缓存信息
function __updateCacheByHttp(routeId)
core.log.info("*****网关从缓存中获取不到路由类型,调用远程接口更新缓存信息*****")
--创建http客户端实例
local httpClient = http:new()
httpClient:set_timeouts(connect_timeout, send_timeout, read_timeout)
httpOpts["path"] = string.format(httpOpts["path"], routeId)
core.log.info("远程调用更新缓存,拼接后的url路径:", httpOpts["path"])
local resp, err = httpClient:request_uri(uri, httpOpts)
if err then
core.log.warn("调用远程接口更新缓存数据失败!")
ngx.status = 500
ngx.say(err)
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
httpClient:close()
--获取是否更新缓存信息成功
local body = core.json.decode(resp.body)
local flag = body["data"]
core.log.info("远程接口更新缓存是否成功标识:", flag)
if (flag == nil) or (flag == false) or (type(flag) ~= "boolean") then
ngx.status = 500
ngx.say("网关系统异常:调用远程接口更新缓存数据失败!")
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
end
--通过redis中的数据校验权限信息
function __checkAuthByRedis(val, routeId, client)
--开放接口直接放行
if val == "0" then
core.log.info("开放接口直接放行! ")
end
if val == "1" then
--受保护接口,只校验token
__checkToken()
core.log.info("受保护接口token认证成功后放行! ")
end
if val == "2" then
--高级接口,判断应用是否有权限
local res = __checkToken()
if res ~= nil then
--验证完token获取权限列表,并验证其是否在列表内
__checkAuth(res, routeId, client)
core.log.info("高级接口校验权限成功后放行! ")
end
end
end
function _M.rewrite(conf, ctx)
core.log.info("执行自定义认证插件rewrite阶段*******************开始进行权限校验******************")
--获取路由id
local routeId = ngx.ctx.api_ctx.route_id
core.log.info("route_id: ", routeId)
-- 访问redis,获取路由类型
local client = __redis_connect()
local val = client:get(string.format(type_key, routeId))
if val ~= nil then
--通过redis缓存中的数据进行权限判断
__checkAuthByRedis(val, routeId, client)
else
--缓存中没有数据,调用http更新缓存数据
__updateCacheByHttp(routeId)
local val = client:get(string.format(type_key, routeId))
if val ~= nil then
--通过redis缓存中的数据进行权限判断
__checkAuthByRedis(val, routeId, client)
else
core.log.warn("调用远程接口更新缓存后,缓存中仍没有路由类型数据!:")
ngx.status = 401
ngx.say("调用远程接口更新缓存后,缓存中仍没有路由类型数据!")
ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
end
end`
httpOpts["path"] = string.format(httpOpts["path"], routeId) ,The route id of this location does not match the expectation,
ngx.ctx.api_ctx.route_id,Use this to get normal
### Error Logs
![1684896738069_CF180F20-A2EB-4e03-81F7-FD08C92A9ECA](https://github.com/apache/apisix/assets/81613579/770146e8-d697-42cf-b006-53bb9d4ca6c1)
### Steps to Reproduce
Call interface
### Environment
- APISIX version (run `apisix version`):3.1.0
- Operating system (run `uname -a`):
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
- etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] moonming commented on issue #9533: bug: Is there any concurrency problem in the execution of the plug-in? The id of the route obtained earlier is changed after being passed to a method for use
Posted by "moonming (via GitHub)" <gi...@apache.org>.
moonming commented on issue #9533:
URL: https://github.com/apache/apisix/issues/9533#issuecomment-1608777060
@lingsamuel are you already check? is this a bug?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] lingsamuel closed issue #9533: bug: Is there any concurrency problem in the execution of the plug-in? The id of the route obtained earlier is changed after being passed to a method for use
Posted by "lingsamuel (via GitHub)" <gi...@apache.org>.
lingsamuel closed issue #9533: bug: Is there any concurrency problem in the execution of the plug-in? The id of the route obtained earlier is changed after being passed to a method for use
URL: https://github.com/apache/apisix/issues/9533
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] RangoStack commented on issue #9533: bug: Is there any concurrency problem in the execution of the plug-in? The id of the route obtained earlier is changed after being passed to a method for use
Posted by "RangoStack (via GitHub)" <gi...@apache.org>.
RangoStack commented on issue #9533:
URL: https://github.com/apache/apisix/issues/9533#issuecomment-1566773138
@naveensrinivasan @huacnlee @jaysonsantos @justinmclean
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] lingsamuel commented on issue #9533: bug: Is there any concurrency problem in the execution of the plug-in? The id of the route obtained earlier is changed after being passed to a method for use
Posted by "lingsamuel (via GitHub)" <gi...@apache.org>.
lingsamuel commented on issue #9533:
URL: https://github.com/apache/apisix/issues/9533#issuecomment-1610997887
Duplicate with #9570, so close this one
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org