r47359 - Merge abort-oldclient-8318: Make the old t.w.client APIs timeout correctly on TLS connections
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Sun, 8 May 2016 07:36:42 -0600 (MDT)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Sun May 8 07:36:26 2016
New Revision: 47359
Added:
trunk/twisted/web/topfiles/8318.bugfix
Modified:
trunk/twisted/web/client.py
trunk/twisted/web/test/test_webclient.py
Log:
Merge abort-oldclient-8318: Make the old t.w.client APIs timeout correctly on TLS connections
Author: lukasa
Reviewer: hawkowl
Fixes: #8318
Modified: trunk/twisted/web/client.py
==============================================================================
--- trunk/twisted/web/client.py (original)
+++ trunk/twisted/web/client.py Sun May 8 07:36:26 2016
@@ -246,7 +246,7 @@
def timeout(self):
self.quietLoss = True
- self.transport.loseConnection()
+ self.transport.abortConnection()
self.factory.noPage(defer.TimeoutError("Getting %s took longer than %s seconds." % (self.factory.url, self.factory.timeout)))
Modified: trunk/twisted/web/test/test_webclient.py
==============================================================================
--- trunk/twisted/web/test/test_webclient.py (original)
+++ trunk/twisted/web/test/test_webclient.py Sun May 8 07:36:26 2016
@@ -90,6 +90,20 @@
return server.NOT_DONE_YET
+class ForeverTakingNoReadingResource(resource.Resource):
+ """
+ L{ForeverTakingNoReadingResource} is a resource that never finishes
+ responding and that removes itself from the read loop.
+ """
+ def __init__(self):
+ resource.Resource.__init__(self)
+
+ def render(self, request):
+ # Stop the producing.
+ request.transport.pauseProducing()
+ return server.NOT_DONE_YET
+
+
class CookieMirrorResource(resource.Resource):
def render(self, request):
l = []
@@ -291,6 +305,7 @@
r.putChild(b"infiniteRedirect", self.infiniteRedirectResource)
r.putChild(b"wait", ForeverTakingResource())
r.putChild(b"write-then-wait", ForeverTakingResource(write=True))
+ r.putChild(b"never-read", ForeverTakingNoReadingResource())
r.putChild(b"error", ErrorResource())
r.putChild(b"nolength", NoLengthResource())
r.putChild(b"host", HostHeaderResource())
@@ -725,6 +740,25 @@
self.assertFailure(second, defer.TimeoutError)])
+ def test_downloadTimeoutsWorkWithoutReading(self):
+ """
+ If the timeout indicated by the C{timeout} parameter to
+ L{client.HTTPDownloader.__init__} elapses without the complete response
+ being received, the L{defer.Deferred} returned by
+ L{client.downloadPage} fires with a L{Failure} wrapping a
+ L{defer.TimeoutError}, even if the remote peer isn't reading data from
+ the socket.
+ """
+ self.cleanupServerConnections = 1
+
+ # The timeout here needs to be slightly longer to give the resource a
+ # change to stop the reading.
+ d = client.downloadPage(
+ self.getURL("never-read"),
+ self.mktemp(), timeout=0.05)
+ return self.assertFailure(d, defer.TimeoutError)
+
+
def test_downloadHeaders(self):
"""
After L{client.HTTPDownloader.deferred} fires, the