Bug 1160873 - Add timeout to requests that are missing them

This commit is contained in:
MikeLing 2015-05-14 14:42:15 +08:00
Родитель bc26cf5ab0
Коммит 4dc05d21b5
3 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -141,6 +141,6 @@ def ping_newrelic(ctx):
try:
request = urllib2.Request('https://api.newrelic.com/deployments.xml',
data, headers)
urllib2.urlopen(request)
urllib2.urlopen(request, timeout=30)
except urllib2.URLError as exp:
print 'Error notifying New Relic: {0}'.format(exp)

Просмотреть файл

@ -74,7 +74,7 @@ class ElasticsearchDocRequest(object):
es_url = "".join([es_host, es_endpoint])
logger.info("Sending data to %s: %s", es_url, self.body)
headers = {'Content-Type': 'text/plain', 'Connection': 'close'}
r = requests.post(es_url, data=json.dumps(self.body), headers=headers)
r = requests.post(es_url, data=json.dumps(self.body), headers=headers, timeout=settings.TREEHERDER_REQUESTS_TIMEOUT)
try:
r.raise_for_status()
except requests.exceptions.HTTPError:
@ -165,7 +165,7 @@ class BugzillaCommentRequest(object):
credentials = {'login': settings.TBPLBOT_EMAIL, 'password': settings.TBPLBOT_PASSWORD}
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
logger.info("Sending data to %s: %s", api_url, self.body)
r = requests.post(api_url, params=credentials, data=json.dumps(self.body), headers=headers)
r = requests.post(api_url, params=credentials, data=json.dumps(self.body), headers=headers, timeout=settings.TREEHERDER_REQUESTS_TIMEOUT)
try:
r.raise_for_status()
except requests.exceptions.HTTPError:

Просмотреть файл

@ -31,7 +31,7 @@ class JsonExtractorMixin(object):
req.add_header('Accept', 'application/json')
req.add_header('Content-Type', 'application/json')
try:
handler = urllib2.urlopen(req)
handler = urllib2.urlopen(req, timeout=settings.TREEHERDER_REQUESTS_TIMEOUT)
encoding = handler.info().get('Content-Encoding')
if encoding and 'gzip' in encoding:
buf = StringIO(handler.read())
@ -52,7 +52,7 @@ class JsonLoaderMixin(object):
req.add_header('Content-Type', 'application/json')
if not data:
data = None
return urllib2.urlopen(req, json.dumps(data))
return urllib2.urlopen(req, json.dumps(data), timeout=settings.TREEHERDER_REQUESTS_TIMEOUT)
class ObjectstoreLoaderMixin(JsonLoaderMixin):