Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
fix(balancer) named SRV entries return hostname properly (#18)
Browse files Browse the repository at this point in the history
Named entries in an SRV record would not return the hostname
properly, but always 'nil'.

See issue #17
  • Loading branch information
Tieske authored Aug 17, 2017
1 parent 12cd7d5 commit 33c582b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions spec/balancer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,28 @@ describe("Loadbalancer", function()
end)

describe("getting targets", function()
it("gets an IP address, port and hostname for named SRV entries", function()
-- this case is special because it does a last-minute `toip` call and hence
-- uses a different code branch
-- See issue #17
dnsA({
{ name = "mashape.com", address = "1.2.3.4" },
})
dnsSRV({
{ name = "gelato.io", target = "mashape.com", port = 8001 },
})
local b = check_balancer(balancer.new {
hosts = {
{name = "gelato.io", port = 123, weight = 100},
},
dns = client,
})
-- run down the wheel twice
local addr, port, host = b:getPeer()
assert.equal("1.2.3.4", addr)
assert.equal(8001, port)
assert.equal("gelato.io", host)
end)
it("gets an IP address and port number round-robin", function()
dnsA({
{ name = "mashape.com", address = "1.2.3.4" },
Expand Down
4 changes: 3 additions & 1 deletion src/resty/dns/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ function objAddr:getPeer(cacheOnly)
if self.ipType == "name" then
-- SRV type record with a named target
local ip, port = dns.toip(self.ip, self.port, cacheOnly)
return ip, port, self.host.name
-- TODO: which is the proper name to return in this case?
-- `self.host.hostname`? or the named SRV entry: `self.ip`?
return ip, port, self.host.hostname
else
-- just an IP address
return self.ip, self.port, self.host.hostname
Expand Down

0 comments on commit 33c582b

Please sign in to comment.