From 5722c604c6f5dc1553674d179ec016ec12e2b090 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 4 Jun 2013 13:34:16 -0400 Subject: [PATCH] retry requests after BadStatusLine --- sdk/python/arvados.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sdk/python/arvados.py b/sdk/python/arvados.py index 61511f5d79..9b145f3d9e 100644 --- a/sdk/python/arvados.py +++ b/sdk/python/arvados.py @@ -16,10 +16,20 @@ from apiclient.discovery import build class CredentialsFromEnv: @staticmethod def http_request(self, uri, **kwargs): + from httplib import BadStatusLine if 'headers' not in kwargs: kwargs['headers'] = {} kwargs['headers']['Authorization'] = 'OAuth2 %s' % os.environ['ARVADOS_API_TOKEN'] - return self.orig_http_request(uri, **kwargs) + try: + return self.orig_http_request(uri, **kwargs) + except BadStatusLine: + # This is how httplib tells us that it tried to reuse an + # existing connection but it was already closed by the + # server. In that case, yes, we would like to retry. + # Unfortunately, we are not absolutely certain that the + # previous call did not succeed, so this is slightly + # risky. + return self.orig_http_request(uri, **kwargs) def authorize(self, http): http.orig_http_request = http.request http.request = types.MethodType(self.http_request, http) -- 2.30.2