mirror of https://github.com/scrapy/scrapy.git
Patches Twisted issue while closing the connection pool on HTTPDownloadHandler
This commit is contained in:
parent
eeb589a4da
commit
d0bf957069
|
|
@ -29,6 +29,7 @@ class HTTP11DownloadHandler(object):
|
|||
self._pool._factory.noisy = False
|
||||
self._contextFactoryClass = load_object(settings['DOWNLOADER_CLIENTCONTEXTFACTORY'])
|
||||
self._contextFactory = self._contextFactoryClass()
|
||||
self._disconnect_timeout = 1
|
||||
|
||||
def download_request(self, request, spider):
|
||||
"""Return a deferred for the HTTP download"""
|
||||
|
|
@ -36,7 +37,24 @@ class HTTP11DownloadHandler(object):
|
|||
return agent.download_request(request)
|
||||
|
||||
def close(self):
|
||||
return self._pool.closeCachedConnections()
|
||||
d = self._pool.closeCachedConnections()
|
||||
# closeCachedConnections will hang on network or server issues, so
|
||||
# we'll manually timeout the deferred.
|
||||
#
|
||||
# Twisted issue addressing this problem can be found here:
|
||||
# https://twistedmatrix.com/trac/ticket/7738.
|
||||
#
|
||||
# closeCachedConnections doesn't handle external errbacks, so we'll
|
||||
# issue a callback after `_disconnect_timeout` seconds.
|
||||
delayed_call = reactor.callLater(self._disconnect_timeout, d.callback, [])
|
||||
|
||||
def cancel_delayed_call(result):
|
||||
if delayed_call.active():
|
||||
delayed_call.cancel()
|
||||
return result
|
||||
|
||||
d.addBoth(cancel_delayed_call)
|
||||
return d
|
||||
|
||||
|
||||
class TunnelError(Exception):
|
||||
|
|
|
|||
Loading…
Reference in New Issue