Skip to contentSkip to conversation

autobuild-run: handle failed network connection

PATCH New Thomas De Schampheleire 2 participants 2 messages Apr 8, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 autobuild-run: handle failed network connection

From: Thomas De Schampheleire <[email protected]>

Due to a network failure, checking of the autobuild-run version or obtaining the toolchain configurations could fail, causing the instance to stop with an exception (and not restarting automatically).

Fix this scenario by catching such errors and continuing with a new build.

---
Note: UNTESTED!

---
 scripts/autobuild-run | 62 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 26 deletions(-)
scripts/autobuild-run +36 -26
index 0e12080..350a137 100755
@@ -158,11 +158,15 @@ def log_write(logf, msg):
     logf.flush()
 
 def check_version():
-    with urlopen_closing('http://autobuild.buildroot.org/version') as r:
-        version = int(decode_bytes(r.readline()).strip())
-    if version > VERSION:
-        print("ERROR: script version too old, please upgrade.")
-        sys.exit(1)
+    try:
+        with urlopen_closing('http://autobuild.buildroot.org/version') as r:
+            version = int(decode_bytes(r.readline()).strip())
+        if version > VERSION:
+            print("ERROR: script version too old, please upgrade.")
+            sys.exit(1)
+    except _urllib.URLError:
+        # couldn't check version, assume it's OK
+        pass
 
 class SystemInfo:
     DEFAULT_NEEDED_PROGS = ["make", "git", "gcc", "timeout"]
@@ -242,27 +246,30 @@ def get_toolchain_configs():
     """
     tc_cfg_uri = 'http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv'
 
-    with urlopen_closing(tc_cfg_uri) as r:
-        l = decode_byte_list(r.readlines())
-    configs = []
-
-    (_, _, _, _, hostarch) = os.uname()
-    if hostarch == 'i686' or hostarch == 'x86_64':
-        hostarch = 'x86'
-
-    for row in csv.reader(l):
-        config = {}
-        config["url"] = row[0]
-        config["hostarch"] = row[1]
-        # Ignore toolchains that are not built for the appropriate
-        # host architecture
-        if hostarch != config["hostarch"]:
-            continue
-        config["libc"] = row[2]
-        with urlopen_closing(config["url"]) as r:
-            config["contents"] = decode_byte_list(r.readlines())
-        configs.append(config)
-    return configs
+    try:
+        with urlopen_closing(tc_cfg_uri) as r:
+            l = decode_byte_list(r.readlines())
+        configs = []
+
+        (_, _, _, _, hostarch) = os.uname()
+        if hostarch == 'i686' or hostarch == 'x86_64':
+            hostarch = 'x86'
+
+        for row in csv.reader(l):
+            config = {}
+            config["url"] = row[0]
+            config["hostarch"] = row[1]
+            # Ignore toolchains that are not built for the appropriate
+            # host architecture
+            if hostarch != config["hostarch"]:
+                continue
+            config["libc"] = row[2]
+            with urlopen_closing(config["url"]) as r:
+                config["contents"] = decode_byte_list(r.readlines())
+            configs.append(config)
+        return configs
+    except _urllib.URLError:
+        return []
 
 def prepare_build(**kwargs):
     """Prepare for the next build of the specified instance
@@ -471,6 +478,9 @@ def gen_config(**kwargs):
 
     # Select a random toolchain configuration
     configs = get_toolchain_configs()
+    if not configs:
+        log_write(log, "WARNING: no toolchain configurations could be retrieved. Network issue?")
+        return -1
     i = randint(0, len(configs) - 1)
     config = configs[i]
 
Signature · 1 line
1.8.5.1
#1 lore raw

PATCH 1/1 autobuild-run: handle failed network connection

Dear Thomas De Schampheleire,

Quoted 9 lines · Thomas De Schampheleire

From: Thomas De Schampheleire <[email protected]>

Due to a network failure, checking of the autobuild-run version or obtaining the toolchain configurations could fail, causing the instance to stop with an exception (and not restarting automatically).

Fix this scenario by catching such errors and continuing with a new build.

Thanks for quickly proposing a patch for this! But I'm wondering if we shouldn't instead fix the main autobuild-run process (which starts the subprocesses) to read the exit code of its subprocesses, and restart them if they fail. This would allow to make sure the subprocesses continue to run, regardless of the reason for which they failed.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com