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 (#19)
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'.

Fixes #17
  • Loading branch information
Tieske authored Aug 17, 2017
1 parent fbc3087 commit d799d44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ History

### 0.6.x (xx-xxx-2017) Fixes and refactor

- Fix: balancer not returning hostname for named SRV entries. See
[issue #17](https://github.com/Mashape/lua-resty-dns-client/issues/17)
- Fix: fix an occasionally failing test
- Refactor: remove metadata from the records, instead store it in its own cache

Expand Down
22 changes: 22 additions & 0 deletions spec/balancer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,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 d799d44

Please sign in to comment.