From b3a0fc30102042be6f5db0c1f644cc21ec69394a Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 10 Oct 2018 16:52:20 +0000 Subject: Catch SSL errors when fetching Gold JSON data. Also increase timeout value when retrying. Change-Id: I14dd3f76fd1a7555c3a5e1bd8c7bf8f214bc8ec0 Reviewed-on: https://pdfium-review.googlesource.com/c/43616 Reviewed-by: Ryan Harrison Commit-Queue: Lei Zhang --- testing/tools/gold.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/testing/tools/gold.py b/testing/tools/gold.py index ce158be319..2987508ccf 100644 --- a/testing/tools/gold.py +++ b/testing/tools/gold.py @@ -7,6 +7,7 @@ import json import os import shlex import shutil +import ssl import urllib2 @@ -72,19 +73,22 @@ class GoldBaseline(object): url = GOLD_BASELINE_URL + ('/' + cl_number_str if cl_number_str else '') json_data = '' - RETRIES = 5 - attempts = 0 - while not json_data and attempts < RETRIES: + MAX_TIMEOUT = 33 # 5 tries. (2, 4, 8, 16, 32) + timeout = 2 + while True: try: - response = urllib2.urlopen(url, timeout=2) + response = urllib2.urlopen(url, timeout=timeout) c_type = response.headers.get('Content-type', '') EXPECTED_CONTENT_TYPE = 'application/json' if c_type != EXPECTED_CONTENT_TYPE: raise ValueError('Invalid content type. Got %s instead of %s' % ( c_type, EXPECTED_CONTENT_TYPE)) json_data = response.read() - attempts += 1 - except (urllib2.HTTPError, urllib2.URLError) as e: + break # If this line is reached, then no exception occurred. + except (ssl.SSLError, urllib2.HTTPError, urllib2.URLError) as e: + timeout *= 2 + if timeout < MAX_TIMEOUT: + continue print ('Error: Unable to read skia gold json from %s: %s' % (url, e)) return None -- cgit v1.2.3