cve-update-nvd2-native: retry all errors and sleep between retries
PATCH 1/2 cve-update-nvd2-native: retry all errors and sleep between retries
From: Peter Marko <[email protected]>
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.
--- meta/recipes-core/meta/cve-update-nvd2-native.bb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
meta/recipes-core/meta/cve-update-nvd2-native.bb +4 -7
@@ -119,6 +119,7 @@ def nvd_request_next(url, api_key, args): import urllib.parse import gzip import http + import time headers = {} if api_key:
@@ -140,13 +141,9 @@ def nvd_request_next(url, api_key, args): r.close() - except UnicodeDecodeError: - # Received garbage, retry - bb.debug(2, "CVE database: received malformed data, retrying (request: %s)" %(full_request)) - pass - except http.client.IncompleteRead: - # Read incomplete, let's try again - bb.debug(2, "CVE database: received incomplete data, retrying (request: %s)" %(full_request)) + except Exception as e: + bb.debug(2, "CVE database: received error (%s), retrying (request: %s)" %(e, full_request)) + time.sleep(6) pass else: return raw_data
Signature · 1 line
2.30.2
PATCH 2/2 cve-update-nvd2-native: increase retry count
From: Peter Marko <[email protected]>
Current 503 errors seem to last several seconds.
In most cases there are two errors and third request succeeds. However sometimes the outage takes more than time needed for two retries and third one also fails.
Extend retry count from 3 to 5 to improve the probablity that the fetcher succeeds.
--- meta/recipes-core/meta/cve-update-nvd2-native.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-core/meta/cve-update-nvd2-native.bb +1 -1
@@ -129,7 +129,7 @@ def nvd_request_next(url, api_key, args): full_request = url + '?' + data - for attempt in range(3): + for attempt in range(5): try: r = urllib.request.urlopen(full_request)
Signature · 1 line
2.30.2
Re: [OE-core][master][mickledore][kirkstone][dunfell][PATCH 2/2] cve-update-nvd2-native: increase retry count
Horrible, but in my testing it works. Thanks Peter!
Ross
Quoted 42 lines · Peter Marko via lists.openembedded.org
From: Peter Marko <[email protected]>
Current 503 errors seem to last several seconds.
In most cases there are two errors and third request succeeds. However sometimes the outage takes more than time needed for two retries and third one also fails.Extend retry count from 3 to 5 to improve the probablity that the fetcher succeeds.
Signed-off-by Peter Marko <[email protected]>---
meta/recipes-core/meta/cve-update-nvd2-native.bb | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)meta/recipes-core/meta/cve-update-nvd2-native.bb +1
-1@@ -129,7 +129,7 @@ def nvd_request_next(url, api_key, args): full_request = url + '?' + data - for attempt in range(3): + for attempt in range(5): try: r = urllib.request.urlopen(full_request)Signature · 10 lines
2.30.2 -=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#184116): https://lists.openembedded.org/g/openembedded-core/message/184116 Mute This Topic: https://lists.openembedded.org/mt/100074007/6875888 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
Re: [OE-core][master][mickledore][kirkstone][dunfell][PATCH 2/2] cve-update-nvd2-native: increase retry count
Peter, what is the probability it passes (for the complete download) with those settings? Is it every time?
Kind regards,
Marta
Quoted 55 lines · Ross Burton
Horrible, but in my testing it works. Thanks Peter!
Ross
Quoted 1 line
On 11 Jul 2023, at 07:36, Peter Marko via lists.openembedded.org
Quoted 11 lines · <[email protected]> wrote:
From: Peter Marko <[email protected]>
Current 503 errors seem to last several seconds.
In most cases there are two errors and third request succeeds. However sometimes the outage takes more than time needed for two retries and third one also fails.Extend retry count from 3 to 5 to improve the probablity that the fetcher succeeds.
Review
Quoted 6 lines
Signed-off-by Peter Marko <[email protected]>---
meta/recipes-core/meta/cve-update-nvd2-native.bb | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)(quoted diff) +0
-0b/meta/recipes-core/meta/cve-update-nvd2-native.bb
Quoted 13 lines
index
a7392405e0..b3d0038c2f100644meta/recipes-core/meta/cve-update-nvd2-native.bb +1
-2@@ -129,7 +129,7 @@ def nvd_request_next(url, api_key, args): full_request = url + '?' + data - for attempt in range(3): + for attempt in range(5): try: r = urllib.request.urlopen(full_request) --Quoted 5 lines
2.30.2
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#184130):
https://lists.openembedded.org/g/openembedded-core/message/184130
Mute This Topic: https://lists.openembedded.org/mt/100074007/5827677
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [OE-core][master][mickledore][kirkstone][dunfell][PATCH 2/2] cve-update-nvd2-native: increase retry count
Quoted 2 lines · Marta Rybczynska
Peter, what is the probability it passes (for the complete download) with those settings? Is it every time?
FWIW, with my testing this morning (I was just doing some other tweaks to the same code) I managed to get a complete download every time over about 8 attempts. Every log had a few 503 errors in, but they all worked with a retry.
Ross
Thank you Peter for debugging this. Could you dump us a log of one of your typical runs to see what the errors are?
We might consider mirroring at some point.
Kind regards,
Marta
Quoted 66 lines · Peter Marko via lists.openembedded.org
From: Peter Marko <[email protected]>
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.
Signed-off-by Peter Marko <[email protected]>--- meta/recipes-core/meta/cve-update-nvd2-native.bb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)meta/recipes-core/meta/cve-update-nvd2-native.bb +4
-7@@ -119,6 +119,7 @@ def nvd_request_next(url, api_key, args): import urllib.parse import gzip import http + import time headers = {} if api_key:@@ -140,13 +141,9 @@ def nvd_request_next(url, api_key, args): r.close() - except UnicodeDecodeError: - # Received garbage, retry - bb.debug(2, "CVE database: received malformed data, retrying (request: %s)" %(full_request)) - pass - except http.client.IncompleteRead: - # Read incomplete, let's try again - bb.debug(2, "CVE database: received incomplete data, retrying (request: %s)" %(full_request)) + except Exception as e: + bb.debug(2, "CVE database: received error (%s), retrying (request: %s)" %(e, full_request)) + time.sleep(6)pass
else:
returnraw_data
--
2.30.2-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#184115):
https://lists.openembedded.org/g/openembedded-core/message/184115
Mute This Topic: https://lists.openembedded.org/mt/100074006/5827677
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Hello,
My testing was done with log increased to warning, and this is a typical outcome:
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=32000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=32000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=58000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=58000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=130000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=130000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=214000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=214000)
Out of 11 runs I had:
- 1 different failure but since at that time I was only catching 503s and thus it crashed I don’t have a cooker log, it was something that remote hang up without providing any data.
- 1 problem that 3 tries were not enough
- 9 times success
But maybe it also depends on region where your machine is doing the requests from or your time when you’re doing the run.
I think the first patch (catching all exceptions) is something really needed and the second one (5 retries) is something not very nice but probably needed for time being. Possibly we could increase the sleep time instead of increasing retries; I’m open to suggestions as I’d like to see the changes merged soon so we can continue with vulnerability handling.
Regards,
Peter
From: Marta Rybczynska <[email protected]>
Sent: Tuesday, July 11, 2023 14:50
To: Marko, Peter (ADV D EU SK BFS1) <[email protected]>
Cc: [email protected]
Subject: Re: [OE-core][master][mickledore][kirkstone][dunfell][PATCH 1/2] cve-update-nvd2-native: retry all errors and sleep between retries
Thank you Peter for debugging this. Could you dump us a log of one of your typical runs to see what the errors are? We might consider mirroring at some point.
Kind regards,
Marta
On Tue, Jul 11, 2023 at 8:37 AM Peter Marko via lists.openembedded.org<http://lists.openembedded.org> <[email protected]<mailto:[email protected]>> wrote:
From: Peter Marko <[email protected]<mailto:[email protected]>>
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.
--- meta/recipes-core/meta/cve-update-nvd2-native.bb<http://cve-update-nvd2-native.bb> | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
meta/recipes-core/meta/cve-update-nvd2-native.bb<http://cve-update-nvd2-native.bb> +4 -7
@@ -119,6 +119,7 @@ def nvd_request_next(url, api_key, args): import urllib.parse import gzip import http + import time headers = {} if api_key:
@@ -140,13 +141,9 @@ def nvd_request_next(url, api_key, args): r.close() - except UnicodeDecodeError: - # Received garbage, retry - bb.debug(2, "CVE database: received malformed data, retrying (request: %s)" %(full_request)) - pass - except http.client.IncompleteRead: - # Read incomplete, let's try again - bb.debug(2, "CVE database: received incomplete data, retrying (request: %s)" %(full_request)) + except Exception as e: + bb.debug(2, "CVE database: received error (%s), retrying (request: %s)" %(e, full_request)) + time.sleep(6) pass else: return raw_data
--
2.30.2
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#184115): https://lists.openembedded.org/g/openembedded-core/message/184115
Mute This Topic: https://lists.openembedded.org/mt/100074006/5827677
Group Owner: [email protected]<mailto:openembedded-core%[email protected]>
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]<mailto:[email protected]>]
-=-=-=-=-=-=-=-=-=-=-=-
Maybe to complete my answer:
With current patch all 11 attempts would pass, but it was iterative approach adding more and more protections. From the tries my conclusions would be:
- without any patch, there is 0% to get DB fetched (with current NVD infrastructure problems)
- with retrying all errors, 90% chance to get it
- with additionally increasing retry count I’d guess 99%
Peter
From: Marko, Peter (ADV D EU SK BFS1)
Sent: Tuesday, July 11, 2023 15:12
To: Marta Rybczynska <[email protected]>
Cc: [email protected]
Subject: RE: [OE-core][master][mickledore][kirkstone][dunfell][PATCH 1/2] cve-update-nvd2-native: retry all errors and sleep between retries
Hello,
My testing was done with log increased to warning, and this is a typical outcome:
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=32000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=32000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=58000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=58000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=130000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=130000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=214000)
WARNING: cve-update-nvd2-native-1.0-r0 do_fetch: CVE database: received error (HTTP Error 503: Service Unavailable), retrying (request: https://services.nvd.nist.gov/rest/json/cves/2.0?startIndex=214000)
Out of 11 runs I had:
- 1 different failure but since at that time I was only catching 503s and thus it crashed I don’t have a cooker log, it was something that remote hang up without providing any data.
- 1 problem that 3 tries were not enough
- 9 times success
But maybe it also depends on region where your machine is doing the requests from or your time when you’re doing the run.
I think the first patch (catching all exceptions) is something really needed and the second one (5 retries) is something not very nice but probably needed for time being. Possibly we could increase the sleep time instead of increasing retries; I’m open to suggestions as I’d like to see the changes merged soon so we can continue with vulnerability handling.
Regards,
Peter
From: Marta Rybczynska <[email protected]<mailto:[email protected]>>
Sent: Tuesday, July 11, 2023 14:50
To: Marko, Peter (ADV D EU SK BFS1) <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [OE-core][master][mickledore][kirkstone][dunfell][PATCH 1/2] cve-update-nvd2-native: retry all errors and sleep between retries
Thank you Peter for debugging this. Could you dump us a log of one of your typical runs to see what the errors are? We might consider mirroring at some point.
Kind regards,
Marta
On Tue, Jul 11, 2023 at 8:37 AM Peter Marko via lists.openembedded.org<http://lists.openembedded.org> <[email protected]<mailto:[email protected]>> wrote:
From: Peter Marko <[email protected]<mailto:[email protected]>>
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.
--- meta/recipes-core/meta/cve-update-nvd2-native.bb<http://cve-update-nvd2-native.bb> | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
meta/recipes-core/meta/cve-update-nvd2-native.bb<http://cve-update-nvd2-native.bb> +4 -7
@@ -119,6 +119,7 @@ def nvd_request_next(url, api_key, args): import urllib.parse import gzip import http + import time headers = {} if api_key:
@@ -140,13 +141,9 @@ def nvd_request_next(url, api_key, args): r.close() - except UnicodeDecodeError: - # Received garbage, retry - bb.debug(2, "CVE database: received malformed data, retrying (request: %s)" %(full_request)) - pass - except http.client.IncompleteRead: - # Read incomplete, let's try again - bb.debug(2, "CVE database: received incomplete data, retrying (request: %s)" %(full_request)) + except Exception as e: + bb.debug(2, "CVE database: received error (%s), retrying (request: %s)" %(e, full_request)) + time.sleep(6) pass else: return raw_data
--
2.30.2
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#184115): https://lists.openembedded.org/g/openembedded-core/message/184115
Mute This Topic: https://lists.openembedded.org/mt/100074006/5827677
Group Owner: [email protected]<mailto:openembedded-core%[email protected]>
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]<mailto:[email protected]>]
-=-=-=-=-=-=-=-=-=-=-=-