Fix: Force delay between docker get calls 84/69884/1
authorBengt Thuree <bthuree@linuxfoundation.org>
Wed, 23 Mar 2022 04:09:06 +0000 (15:09 +1100)
committerBengt Thuree <bthuree@linuxfoundation.org>
Wed, 23 Mar 2022 04:09:06 +0000 (15:09 +1100)
Docker has introduced a 429 error return code
if there site is called to quickly.

Delay 0.5 seconds after every pull, to avoid to fast requests.

Signed-off-by: Bengt Thuree <bthuree@linuxfoundation.org>
Issue-ID: RELENG-3711
Change-Id: Ic5ac8da65903c0445092d74168ff9fd1dc0068bd

lftools/nexus/release_docker_hub.py

index 53d5096..813c926 100644 (file)
@@ -46,6 +46,7 @@ import os
 import re
 import socket
 from multiprocessing.dummy import Pool as ThreadPool
+from time import sleep
 
 import docker
 import requests
@@ -305,6 +306,7 @@ class DockerTagClass(TagClass):
         while retries < 20:
             try:
                 r = _request_get(self._docker_base + "/" + combined_repo_name + "/tags")
+                sleep(0.5)
                 break
             except requests.HTTPError as excinfo:
                 log.debug("Fetching Docker Hub tags. {}".format(excinfo))
@@ -314,6 +316,11 @@ class DockerTagClass(TagClass):
                     return
 
         log.debug("r.status_code = {}, ok={}".format(r.status_code, r.status_code == requests.codes.ok))
+        if r.status_code == 429:
+            # Speed throttling in effect. Cancel program
+            raise requests.HTTPError(
+                "Speed throttling in effect. To fast accessing dockerhub for tags.\n {}".format(r.text)
+            )
         if r.status_code == requests.codes.ok:
             raw_tags = r.text
             raw_tags = raw_tags.replace("}]", "")