From 14403c2122a7e98204357fa72e20946f9bba8ef4 Mon Sep 17 00:00:00 2001 From: Yumi Yukimura Date: Fri, 21 Jun 2024 05:41:13 +0800 Subject: [PATCH] roomservice: Set timeout when accessing GitHub * Bypasses the literally infinite timeout for users who have limited access to GitHub (before: 2m13.749s, after: 0m14.354s) * The timeouts should be enough for users who have freedom internet access, even ADSL network connection shouldn't take that long... Test: 1. Execute `source build/envsetup.sh` 2. `breakfast` a existing device 3. Add "0.0.0.1 github.com" and "0.0.0.1 raw.githubusercontent.com" to /etc/hosts 4. `breakfast` any device, observe that it should not take up to minutes to quit Change-Id: Ib90e69c75a50e66b47e6245cb6d0521351b5c71b --- build/tools/roomservice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/tools/roomservice.py b/build/tools/roomservice.py index 55e5ed66..835d792d 100755 --- a/build/tools/roomservice.py +++ b/build/tools/roomservice.py @@ -68,7 +68,7 @@ def add_auth(githubreq): if not depsonly: githubreq = urllib.request.Request("https://raw.githubusercontent.com/LineageOS/mirror/main/default.xml") try: - result = ElementTree.fromstring(urllib.request.urlopen(githubreq).read().decode()) + result = ElementTree.fromstring(urllib.request.urlopen(githubreq, timeout=10).read().decode()) except urllib.error.URLError: print("Failed to fetch data from GitHub") sys.exit(1) @@ -269,7 +269,7 @@ def get_default_or_fallback_revision(repo_name): githubreq = urllib.request.Request("https://api.github.com/repos/LineageOS/" + repo_name + "/branches") add_auth(githubreq) - result = json.loads(urllib.request.urlopen(githubreq).read().decode()) + result = json.loads(urllib.request.urlopen(githubreq, timeout=5).read().decode()) if has_branch(result, default_revision): return default_revision