Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dns pool logic #179

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions regress/178-last-resolver.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
_=[[
. "${0%%/*}/regress.sh"
exec runlua "$0" "$@"
]]
require"regress".export".*"

local pool = dns.getpool()
local r = pool:get()
pool:put(r)
local q = pool:get()
check(r == q, "resolver not reused")

say"OK"
14 changes: 5 additions & 9 deletions src/dns.resolvers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,10 @@ local loader = function(loader, ...)
local res
while true do
local cache_len = #self.cache
if cache_len > 1 then
if cache_len > 0 then
res = self.cache[cache_len]
self.cache[cache_len] = nil
if res then
break
else
if deadline and deadline <= monotime() then
return nil, ETIMEDOUT
end
self.condvar:wait(totimeout(deadline))
end
break
elseif self.alive.n < self.hiwat then
local why
res, why = resolver.new(self.resconf, self.hosts, self.hints)
Expand All @@ -134,6 +127,9 @@ local loader = function(loader, ...)
end
break
end
if not self.condvar:wait(totimeout(deadline)) then
return nil, ETIMEDOUT
end
end
self.alive:add(res)
return res
Expand Down