Auto merge of #2265 - daira:2263.fix-rpc-error-reporting, r=daira

Fix an error reporting bug due to BrokenPipeError and ConnectionResetError not existing in Python 2

refs #2263

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
zkbot 2017-04-16 16:56:16 +00:00
commit ab3c2fe7b0
1 changed files with 7 additions and 8 deletions

View File

@ -118,19 +118,18 @@ class AuthServiceProxy(object):
try:
self.__conn.request(method, path, postdata, headers)
return self._get_response()
except httplib.BadStatusLine as e:
if e.line == "''": # if connection was closed, try again
except Exception as e:
# If connection was closed, try again.
# Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset.
# ConnectionResetError happens on FreeBSD with Python 3.4.
# These classes don't exist in Python 2.x, so we can't refer to them directly.
if ((isinstance(e, httplib.BadStatusLine) and e.line == "''")
or e.__class__.__name__ in ('BrokenPipeError', 'ConnectionResetError')):
self.__conn.close()
self.__conn.request(method, path, postdata, headers)
return self._get_response()
else:
raise
except (BrokenPipeError,ConnectionResetError):
# Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset
# ConnectionResetError happens on FreeBSD with Python 3.4
self.__conn.close()
self.__conn.request(method, path, postdata, headers)
return self._get_response()
def __call__(self, *args):
AuthServiceProxy.__id_count += 1