Retry the macOS admission check after a truncated API response (#17859)

json.load in Api.get raises http.client.IncompleteRead when GitHub drops
a response partway. That is an http.client.HTTPException, which wait()
did not catch, so one dropped response failed the "Wait for a macOS
runner" job and skipped the macOS unit tests. wait() now catches
HTTPException and counts it as a failed read like the other API errors,
then polls again. URLError comes out of the tuple because OSError
already covers it.
This commit is contained in:
Kris Austin 2026-11-26 10:49:29 -06:00 • committed by GitHub
parent d42123d2f1
commit d528c0ea9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -36,6 +36,7 @@ POLL_SECONDS and GITHUB_API_URL.
"""
import datetime
import http.client
import json
import os
import sys
@ -228,7 +229,7 @@ def wait(measure_now, limit, wait_minutes, poll_seconds,
while True:
try:
total, lines = measure_now()
except (urllib.error.URLError, OSError, ValueError, KeyError, TypeError) as error:
except (http.client.HTTPException, OSError, ValueError, KeyError, TypeError) as error:
failures += 1
log(f"::warning title=macOS admission::Could not read the queue ({error}).")
if failures >= FAILURES_BEFORE_ADMIT:

View file

@ -5,6 +5,7 @@ Run from the repo root: python -m unittest discover -s scripts/tests -v
"""
import datetime
import http.client
import os
import sys
import unittest
@ -379,6 +380,10 @@ class WaitTest(unittest.TestCase):
reason, _ = self.run_wait([error, error, error])
self.assertEqual(reason, "the queue could not be read")
def test_retries_after_a_truncated_response(self):
error = http.client.IncompleteRead(b"", 148323)
self.assertEqual(self.run_wait([error, 4]), ("a runner is free", 120))
def test_a_good_read_resets_the_error_count(self):
error = urllib.error.URLError("rate limited")
reason, _ = self.run_wait([error, error, 5, error, error, 3])