Merge pull request #2529 from scrapy/backport-1.2-pr2496-dns-float

[backport][1.2] Enforce DNS resolution timeout
This commit is contained in:
Mikhail Korobov 2017-02-03 02:30:12 +05:00 committed by GitHub
commit 10954fc74b
1 changed files with 5 additions and 2 deletions

View File

@ -16,8 +16,11 @@ class CachingThreadedResolver(ThreadedResolver):
def getHostByName(self, name, timeout=None):
if name in dnscache:
return defer.succeed(dnscache[name])
if not timeout:
timeout = self.timeout
# in Twisted<=16.6, getHostByName() is always called with
# a default timeout of 60s (actually passed as (1, 3, 11, 45) tuple),
# so the input argument above is simply overridden
# to enforce Scrapy's DNS_TIMEOUT setting's value
timeout = (self.timeout,)
d = super(CachingThreadedResolver, self).getHostByName(name, timeout)
d.addCallback(self._cache_result, name)
return d