Skip to content

Commit

Permalink
fix(DNS): support SRV with port 0 (#6739)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Mar 31, 2022
1 parent 56e87df commit de4e0bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apisix/discovery/dns/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ function _M.nodes(service_name)
local nodes = core.table.new(#records, 0)
for i, r in ipairs(records) do
if r.address then
nodes[i] = {host = r.address, weight = r.weight or 1, port = r.port or port}
local node_port = r.port
if not node_port or node_port == 0 then
-- if the port is zero, fallback to use the default
node_port = port
end

nodes[i] = {host = r.address, weight = r.weight or 1, port = node_port}
if r.priority then
-- for SRV record, nodes with lower priority are chosen first
nodes[i].priority = -r.priority
Expand Down
2 changes: 2 additions & 0 deletions t/coredns/db.test.local
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ split-weight.srv 86400 IN SRV 10 0 1980 C
priority.srv 86400 IN SRV 10 60 1979 A
priority.srv 86400 IN SRV 20 60 1980 B

zero.srv 86400 IN SRV 10 60 0 A

; a domain has both SRV & A records
srv-a 86400 IN SRV 10 60 1980 A
srv-a IN A 127.0.0.1
17 changes: 17 additions & 0 deletions t/discovery/dns/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,20 @@ upstreams:
proxy request to 127.0.0.1:1980
--- response_body
hello world
=== TEST 14: SRV (port is 0)
--- apisix_yaml
upstreams:
- service_name: "zero.srv.test.local"
discovery_type: dns
type: roundrobin
id: 1
--- error_log
connect() failed
--- error_code: 502
--- grep_error_log eval
qr/proxy request to \S+/
--- grep_error_log_out
proxy request to 127.0.0.1:80

0 comments on commit de4e0bf

Please sign in to comment.