mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-25 03:32:15 +01:00
Implement retries on http
There is a bug either in buildservice or in iChain which sometimes truncates data and sends empty Content-Length header (see bnc#656281). This patch makes osc retry request to workaround this problem. The number of retries are configurable in config file as http_retries.
This commit is contained in:
parent
ebe2f6390c
commit
a285c83794
@ -85,6 +85,7 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org',
|
|||||||
'debug': '0',
|
'debug': '0',
|
||||||
'http_debug': '0',
|
'http_debug': '0',
|
||||||
'http_full_debug': '0',
|
'http_full_debug': '0',
|
||||||
|
'http_retries': '3',
|
||||||
'verbose': '1',
|
'verbose': '1',
|
||||||
'traceback': '0',
|
'traceback': '0',
|
||||||
'post_mortem': '0',
|
'post_mortem': '0',
|
||||||
@ -237,6 +238,9 @@ apiurl = %(apiurl)s
|
|||||||
# show HTTP traffic useful for debugging
|
# show HTTP traffic useful for debugging
|
||||||
#http_debug = 1
|
#http_debug = 1
|
||||||
|
|
||||||
|
# number of retries on HTTP transfer
|
||||||
|
#http_retries = 3
|
||||||
|
|
||||||
# Skip signature verification of packages used for build.
|
# Skip signature verification of packages used for build.
|
||||||
#no_verify = 1
|
#no_verify = 1
|
||||||
|
|
||||||
|
15
osc/core.py
15
osc/core.py
@ -4494,8 +4494,19 @@ def streamfile(url, http_meth = http_GET, bufsize=8192, data=None, progress_obj=
|
|||||||
until EOF is reached. After each read bufsize bytes are yielded to the
|
until EOF is reached. After each read bufsize bytes are yielded to the
|
||||||
caller.
|
caller.
|
||||||
"""
|
"""
|
||||||
f = http_meth.__call__(url, data = data)
|
cl = ''
|
||||||
cl = f.info().get('Content-Length')
|
retries = 0
|
||||||
|
# Repeat requests until we get reasonable Content-Length header
|
||||||
|
# Server (or iChain) is corrupting data at some point, see bnc#656281
|
||||||
|
while cl == '':
|
||||||
|
if retries >= int(conf.config['http_retries']):
|
||||||
|
raise oscerr.OscIOError(None, 'Content-Length is empty for %s, protocol violation' % url)
|
||||||
|
retries = retries + 1
|
||||||
|
if retries > 1 and conf.config['http_debug']:
|
||||||
|
print >>sys.stderr, '\n\nRetry %d --' % (retries - 1), url
|
||||||
|
f = http_meth.__call__(url, data = data)
|
||||||
|
cl = f.info().get('Content-Length')
|
||||||
|
|
||||||
if cl is not None:
|
if cl is not None:
|
||||||
cl = int(cl)
|
cl = int(cl)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user