cve-update-nvd2-native: retry all errors and sleep between retries

Last couple days it is not possible to update NVD DB as servers
are returning lot of errors.
Mostly "HTTP Error 503: Service Unavailable" is observed but
sporadially also some others.

Retrying helps in most cases, so extend retries to all errors.

Additionally add sleep which is recommended by NVD between requests.
These retries are already implemented between successful requests,
but giving servers time between failed ones is important, too.

(From OE-Core rev: c061bcd54fc8b62ea9a005f422a17ca46eac68c2)

Signed-off-by: Peter Marko <peter.marko@siemens.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 88dad8f198baa80af5ab576498f4df6ed639d551)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
This commit is contained in:
Peter Marko
2023-07-11 08:36:28 +02:00
committed by Steve Sakoman
parent bd4b28bb37
commit d6bf614ab4

View File

@@ -119,6 +119,7 @@ def nvd_request_next(url, api_key, args):
import urllib.parse import urllib.parse
import gzip import gzip
import http import http
import time
headers = {} headers = {}
if api_key: if api_key:
@@ -140,13 +141,9 @@ def nvd_request_next(url, api_key, args):
r.close() r.close()
except UnicodeDecodeError: except Exception as e:
# Received garbage, retry bb.debug(2, "CVE database: received error (%s), retrying (request: %s)" %(e, full_request))
bb.debug(2, "CVE database: received malformed data, retrying (request: %s)" %(full_request)) time.sleep(6)
pass
except http.client.IncompleteRead:
# Read incomplete, let's try again
bb.debug(2, "CVE database: received incomplete data, retrying (request: %s)" %(full_request))
pass pass
else: else:
return raw_data return raw_data