Skip to content

Commit b6b550f

Browse files
TECH_DEBT: Bound the HTTP calls in get_deployed_commit.py with a timeout
Neither urlopen call passed a timeout, and the script never sets a global socket default, so both used urlopen's default of blocking indefinitely. An unresponsive /api/info endpoint or GitHub API would hang the Summarize job until the Azure DevOps job timeout killed it, rather than failing the step with a usable error. - Add an HTTP_TIMEOUT_SECONDS constant of 30 seconds - Pass it to the /api/info request and the GitHub commits request, so both share the same budget A timeout on the /api/info call raises into the existing handler and exits through fail(); a timeout while resolving the full hash prints the existing warnings and leaves FromCommit as the short hash. Verified against qa2 that the normal path is unaffected: 78b98b4 still resolves to 78b98b4.
1 parent de90080 commit b6b550f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Scripts/get_deployed_commit.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
REPO_COMMITS_API_ROOT = 'https://api.github.com/repos/lantanagroup/link-cloud/commits/'
2626

27+
# urlopen blocks indefinitely by default, which would hang the pipeline job rather than
28+
# fail it. Bound every HTTP call to the same budget.
29+
HTTP_TIMEOUT_SECONDS = 30
30+
2731
def fail(msg: str):
2832
print(f"ERROR: {msg}", file=sys.stderr)
2933
sys.exit(1)
@@ -78,7 +82,7 @@ def main():
7882
info_url,
7983
headers={'Accept': 'application/json'}
8084
)
81-
with urllib.request.urlopen(request) as response:
85+
with urllib.request.urlopen(request, timeout=HTTP_TIMEOUT_SECONDS) as response:
8286
body = response.read().decode("utf-8")
8387
except Exception as e:
8488
fail(f"Failed to GET {info_url}: {e}")
@@ -109,7 +113,7 @@ def main():
109113
f"{REPO_COMMITS_API_ROOT}{commit}",
110114
headers={'Accept': 'application/vnd.github.sha'}
111115
)
112-
with urllib.request.urlopen(request) as response:
116+
with urllib.request.urlopen(request, timeout=HTTP_TIMEOUT_SECONDS) as response:
113117
full_commit = response.read().decode("utf-8").strip()
114118

115119
if len(full_commit) == 40:

0 commit comments

Comments
 (0)