You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/08/23 08:15:31 UTC
[GitHub] [apisix] zhikaichen123 opened a new issue #4874: CNAME域名解析bug
zhikaichen123 opened a new issue #4874:
URL: https://github.com/apache/apisix/issues/4874
### Issue description
#### 场景说明:
通过核心网关配置,访问域名为yhk.market.alicloudapi.com的ai服务,调用报503异常,看日记记录提示:
**failed to query the DNS server: recursion detected**
简单说明:dns域名解析出现递归,apisix转发cname这块不支持2层以上,但是自己搭建的容器集群正常解析,只是生产环境阿里的容器解析有问题
#### 日记记录:
```html
2021/08/23 15:14:38 [error] 55#55: *309865 [lua] resolver.lua:35: parse_domain(): failed to parse domain: yhk.market.alicloudapi.com, error: failed to query the DNS server: recursion detected, client: 172.21.1.190, server: _, request: "POST /ai/ocr/idcard HTTP/1.1", host: "gw.winnermedical.com"
2021/08/23 15:14:38 [error] 55#55: *309865 [lua] init.lua:178: parse_domain_for_nodes(): dns resolver domain: yhk.market.alicloudapi.com error: failed to query the DNS server: recursion detected, client: 172.21.1.190, server: _, request: "POST /ai/ocr/idcard HTTP/1.1", host: "gw.winnermedical.com"
2021/08/23 15:14:38 [error] 55#55: *309865 [lua] init.lua:482: http_access_phase(): failed to set upstream: no valid upstream node, client: 172.21.1.190, server: _, request: "POST /ai/ocr/idcard HTTP/1.1", host: "gw.winnermedical.com"
```
#### 找到报错原始位置
```html
function _M.parse_domain(host)
local ip_info, err = utils.dns_parse(host)
if not ip_info then
log.error("failed to parse domain: ", host, ", error: ",err)
return nil, err
end
log.info("parse addr: ", json.delay_encode(ip_info))
log.info("resolver: ", json.delay_encode(utils.get_resolver()))
log.info("host: ", host)
if ip_info.address then
log.info("dns resolver domain: ", host, " to ", ip_info.address)
return ip_info.address
end
return nil, "failed to parse domain"
end
function _M.resolve(self, domain, selector)
local client = self.client
-- this function will dereference the CNAME records
local answers, err = client.resolve(domain)
if not answers then
return nil, "failed to query the DNS server: " .. err
end
if answers.errcode then
return nil, "server returned error code: " .. answers.errcode
.. ": " .. answers.errstr
end
if selector == _M.RETURN_ALL then
log.info("dns resolve ", domain, ", result: ", json.delay_encode(answers))
for _, answer in ipairs(answers) do
if answer.type == client.TYPE_SRV then
return resolve_srv(client, answers)
end
end
return table.deepcopy(answers)
end
local idx = math_random(1, #answers)
local answer = answers[idx]
local dns_type = answer.type
if dns_type == client.TYPE_A or dns_type == client.TYPE_AAAA then
log.info("dns resolve ", domain, ", result: ", json.delay_encode(answer))
return table.deepcopy(answer)
end
return nil, "unsupport DNS answer"
end
```
#### 找到最终原因
resolver.lua:35: parse_domain(): failed to parse domain: yhk.market.alicloudapi.com, error: failed to query the DNS server: recursion detected
#### 文件路线:
init.lua(384) -> upstream.lua(270) -> resolver.lua(33) -> utils.lua() -> client.lua(102)
## 总结:暂时无解!
### Environment
apisxi 2.6版本,在阿里的k8s容器运行
### Steps to reproduce
如上说明
### Actual result
如上说明
### Error log
2021/08/23 15:14:38 [error] 55#55: *309865 [lua] resolver.lua:35: parse_domain(): failed to parse domain: yhk.market.alicloudapi.com, error: failed to query the DNS server: recursion detected, client: 172.21.1.190, server: _, request: "POST /ai/ocr/idcard HTTP/1.1", host: "gw.winnermedical.com"
2021/08/23 15:14:38 [error] 55#55: *309865 [lua] init.lua:178: parse_domain_for_nodes(): dns resolver domain: yhk.market.alicloudapi.com error: failed to query the DNS server: recursion detected, client: 172.21.1.190, server: _, request: "POST /ai/ocr/idcard HTTP/1.1", host: "gw.winnermedical.com"
2021/08/23 15:14:38 [error] 55#55: *309865 [lua] init.lua:482: http_access_phase(): failed to set upstream: no valid upstream node, client: 172.21.1.190, server: _, request: "POST /ai/ocr/idcard HTTP/1.1", host: "gw.winnermedical.com"
### Expected result
_No response_
--
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] zhikaichen123 closed issue #4874: CNAME域名解析bug
Posted by GitBox <gi...@apache.org>.
zhikaichen123 closed issue #4874:
URL: https://github.com/apache/apisix/issues/4874
--
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] zhikaichen123 commented on issue #4874: CNAME域名解析bug
Posted by GitBox <gi...@apache.org>.
zhikaichen123 commented on issue #4874:
URL: https://github.com/apache/apisix/issues/4874#issuecomment-904430469
> When I try to reproduce it via:
>
> ```
> === TEST 13: set route(with upstream)
> --- FIRST
> --- config
> location /t {
> content_by_lua_block {
> local t = require("lib.test_admin").test
> local code, body = t('/apisix/admin/upstreams/1',
> ngx.HTTP_PUT,
> [[{
> "nodes": {
> "yhk.market.alicloudapi.com:1980": 1
> },
> "type": "roundrobin",
> "desc": "new upstream"
> }]]
> )
>
> if code >= 300 then
> ngx.status = code
> ngx.say(body)
> return
> end
>
> local code, body = t('/apisix/admin/routes/1',
> ngx.HTTP_PUT,
> [[{
> "uri": "/server_port",
> "upstream_id": "1"
> }]]
> )
>
> if code >= 300 then
> ngx.status = code
> end
> ngx.say(body)
> }
> }
> --- request
> GET /t
> --- response_body
> passed
> --- no_error_log
> [error]
>
>
>
> === TEST 14: roundrobin
> --- config
> location /t {
> content_by_lua_block {
> local t = require("lib.test_admin").test
> local bodys = {}
> for i = 1, 3 do
> local _, _, body = t('/server_port', ngx.HTTP_GET)
> bodys[i] = body
> end
> table.sort(bodys)
> ngx.say(table.concat(bodys, ", "))
> }
> }
> --- request
> GET /t
> --- response_body
> 1980, 1981, 1981
> --- no_error_log
> [error]
> ```
>
> I got error log `run(): proxy request to 47.110.211.55:1980`, which is equal to the result got via dig:
>
> ```
> dig yhk.market.alicloudapi.com
>
> ; <<>> DiG 9.16.1-Ubuntu <<>> yhk.market.alicloudapi.com
> ;; global options: +cmd
> ;; Got answer:
> ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57466
> ;; flags: qr rd ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
> ;; WARNING: recursion requested but not available
>
> ;; QUESTION SECTION:
> ;yhk.market.alicloudapi.com. IN A
>
> ;; ANSWER SECTION:
> yhk.market.alicloudapi.com. 0 IN CNAME d6e9851ee5654feb8a3060c085e57bd4-cn-hangzhou.alicloudapi.com.
> d6e9851ee5654feb8a3060c085e57bd4-cn-hangzhou.alicloudapi.com. 0 IN A 47.110.211.55
>
> ;; Query time: 39 msec
> ;; SERVER: 172.24.80.1#53(172.24.80.1)
> ;; WHEN: 二 8月 24 16:05:39 CST 2021
> ;; MSG SIZE rcvd: 220
> ```
>
> No resolver error was found.
谢谢回复!是这样的
直接在ECS上运行,原始域名的跟cname域名都能正常转发; 部署在阿里的k8s集群上,就会报上面的错误
--
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] zhikaichen123 commented on issue #4874: CNAME域名解析bug
Posted by GitBox <gi...@apache.org>.
zhikaichen123 commented on issue #4874:
URL: https://github.com/apache/apisix/issues/4874#issuecomment-906019336
谢谢spacewander的帮忙,解决方案我已经找到了,如下:
#### 集群dnsPolicy配置和场景说明
```html
ACK支持通过 dnsPolicy字段为每个Pod配置不同的DNS策略。目前ACK集群支持四种策略:
1. ClusterFirst:通过CoreDNS来做域名解析,Pod内/etc/resolv.conf配置的DNS服务地址是集群DNS服务的kube-dns地址。该策略是集群工作负载的默认策略。
2. None:忽略集群DNS策略,需要您提供dnsConfig字段来指定DNS配置信息。
3. Default:Pod直接继承集群节点的域名解析配置。即在ACK集群直接使用ECS的/etc/resolv.conf文件(文件内配置的是阿里云DNS服务)。
4. ClusterFirstWithHostNetwork:强制在hostNetWork网络模式下使用ClusterFirst策略(默认使用Default策略)。
```
```html
apiVersion: v1
kind: Pod
metadata:
name: alpine
namespace: default
spec:
containers:
- image: alpine
command:
- sleep
- "10000"
imagePullPolicy: Always
name: alpine
dnsPolicy: Default
```
关键:dnsPolicy: Default
--
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] spacewander commented on issue #4874: CNAME域名解析bug
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4874:
URL: https://github.com/apache/apisix/issues/4874#issuecomment-904421105
When I try to reproduce it via:
```
=== TEST 13: set route(with upstream)
--- FIRST
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/upstreams/1',
ngx.HTTP_PUT,
[[{
"nodes": {
"yhk.market.alicloudapi.com:1980": 1
},
"type": "roundrobin",
"desc": "new upstream"
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/server_port",
"upstream_id": "1"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 14: roundrobin
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local bodys = {}
for i = 1, 3 do
local _, _, body = t('/server_port', ngx.HTTP_GET)
bodys[i] = body
end
table.sort(bodys)
ngx.say(table.concat(bodys, ", "))
}
}
--- request
GET /t
--- response_body
1980, 1981, 1981
--- no_error_log
[error]
```
I got error log `run(): proxy request to 47.110.211.55:1980`, which is equal to the result got via dig:
```
dig yhk.market.alicloudapi.com
; <<>> DiG 9.16.1-Ubuntu <<>> yhk.market.alicloudapi.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57466
;; flags: qr rd ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;yhk.market.alicloudapi.com. IN A
;; ANSWER SECTION:
yhk.market.alicloudapi.com. 0 IN CNAME d6e9851ee5654feb8a3060c085e57bd4-cn-hangzhou.alicloudapi.com.
d6e9851ee5654feb8a3060c085e57bd4-cn-hangzhou.alicloudapi.com. 0 IN A 47.110.211.55
;; Query time: 39 msec
;; SERVER: 172.24.80.1#53(172.24.80.1)
;; WHEN: 二 8月 24 16:05:39 CST 2021
;; MSG SIZE rcvd: 220
```
No resolver error was found.
--
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] spacewander commented on issue #4874: CNAME域名解析bug
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4874:
URL: https://github.com/apache/apisix/issues/4874#issuecomment-905247625
Could you find a way to reproduce it without Alicloud? APISIX is expected to support any levels of CNAME resolve. The error message indicated that the CNAME configuration of the environment may cause an infinite recursive resolution.
--
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