Skip to content

Commit

Permalink
Fixed dns resolver bug after reboot, #119
Browse files Browse the repository at this point in the history
  • Loading branch information
bakwc committed Sep 7, 2020
1 parent 792b611 commit 01f2ad7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pysyncobj/dns_resolver.py
Expand Up @@ -18,7 +18,7 @@ def setTimeouts(self, cacheTime, failCacheTime):

def resolve(self, hostname):
currTime = monotonicTime()
cachedTime, ips = self.__cache.get(hostname, (0, []))
cachedTime, ips = self.__cache.get(hostname, (-self.__failCacheTime-1, []))
timePassed = currTime - cachedTime
if (timePassed > self.__cacheTime) or (not ips and timePassed > self.__failCacheTime):
prevIps = ips
Expand Down
8 changes: 8 additions & 0 deletions test_syncobj.py
Expand Up @@ -6,6 +6,7 @@
import threading
import sys
import pysyncobj.pickle as pickle
import pysyncobj.dns_resolver as dns_resolver

if sys.version_info >= (3, 0):
xrange = range
Expand Down Expand Up @@ -2006,3 +2007,10 @@ def test_zeroDeployVersions():
assert 'someMethod' not in o1._methodToID
assert 'thirdMethod' not in o1._methodToID
assert 'lastMethod' not in o1._methodToID


def test_dnsResolverBug(monkeypatch):
monkeypatch.setattr(dns_resolver, "monotonicTime", lambda: 0.0)
resolver = dns_resolver.DnsCachingResolver(600, 30)
ip = resolver.resolve('localhost')
assert ip == '127.0.0.1'

0 comments on commit 01f2ad7

Please sign in to comment.