Improved persistent connection handling by retrying closed connections.

This commit is contained in:
Bastian Kleineidam 2009-03-06 08:15:34 +01:00
parent 7d23e6941b
commit 58925b21d3
2 changed files with 23 additions and 5 deletions

View file

@ -7,12 +7,15 @@
text logger which also honors the system settings.
Closes: SF bug #2579899
* Improved progress dialog in GUI client.
* Improved progress dialog in GUI client: show active and queued URLs.
* The content size of downloads is now shown again.
* Make output more concise by not logging duplicate cached URLs.
* Improved persistent connection handling: retry connecting to HTTP
servers which close persistent connections unexpectedly.
5.0.2 "All the boys love Mandy Lane" (released 13.2.2009)
* Properly detect location of the log configuration file in the Windows

View file

@ -218,7 +218,7 @@ Use URL `%(newurl)s' instead for checking.""") % {
if response is not None:
response.close()
try:
response = self._get_http_response()
response = self._try_http_response()
except httplib.BadStatusLine:
# some servers send empty HEAD replies
if self.method == "HEAD":
@ -246,7 +246,7 @@ Use URL `%(newurl)s' instead for checking.""") % {
valid=False)
return response
response.close()
response = self._get_http_response()
response = self._try_http_response()
# restore old proxy settings
self.proxy, self.proxyauth = oldproxy
try:
@ -394,7 +394,7 @@ Use URL `%(newurl)s' instead for checking.""") % {
return -1, response
# new response data
response.close()
response = self._get_http_response()
response = self._try_http_response()
tries += 1
return tries, response
@ -445,6 +445,21 @@ Use URL `%(newurl)s' instead for checking.""") % {
if modified:
self.add_info(_("Last modified %(date)s.") % {"date": modified})
def _try_http_response (self):
"""Try to get a HTTP response object. For reused persistent
connections that the server closed unexpected, a new connection
will be opened.
"""
try:
return self._get_http_response()
except socket.error, msg:
if msg.args[0] == 32 and self.reused_connection:
# server closed persistent connection - retry
self.persistent = False
self.close_connection()
return self._get_http_response()
raise
def _get_http_response (self):
"""
Send HTTP request and get response object.
@ -558,7 +573,7 @@ Use URL `%(newurl)s' instead for checking.""") % {
@rtype: string
"""
self.method = "GET"
response = self._get_http_response()
response = self._try_http_response()
response = self.follow_redirections(response, set_result=False)[1]
self.headers = response.msg
if self._data is None: