Repository navigation
fix: retry Apple gateway 502/503/504 during authentication - #170
Conversation
| return nil | ||
| // Apple's gateway answers 502 / 503 / 504 for a share of requests; this | ||
| // read-only request is safe to repeat. | ||
| for attempt in 1...5 { |
There was a problem hiding this comment.
This repeats sendRetryingTransientErrors from HTTPClient.swift. Could this call go through the same helper, so the retry rule lives in one place?
There was a problem hiding this comment.
Done in 97e7799: both calls now use one TransientRetryPolicy.send.
| while true { | ||
| let (data, response) = try await self.urlSession.data(for: request, delegate: nil) | ||
| if let http = response as? HTTPURLResponse, | ||
| [502, 503, 504].contains(http.statusCode), |
There was a problem hiding this comment.
5, 300 and [502, 503, 504] now appear in two places. Could they be named constants, for example maxAttempts, retryDelay and transientStatusCodes?
There was a problem hiding this comment.
Done in 97e7799: maxAttempts, retryDelay and transientStatusCodes live in TransientRetryPolicy.
| } | ||
|
|
||
| @Test("apiCall retries 504 answers when asked to") | ||
| func apiCallRetriesTransientErrors() async throws { |
There was a problem hiding this comment.
This test really sleeps 300 ms plus 600 ms. Could the delay be injectable, so the test runs instantly?
There was a problem hiding this comment.
Done in 97e7799: retryDelay is injectable and tests set it to zero.
| guard let httpResponse = response as? HTTPURLResponse else { | ||
| return nil | ||
| } | ||
| if [502, 503, 504].contains(httpResponse.statusCode), attempt < 5 { |
There was a problem hiding this comment.
Is there a test for this retry path? The two new tests only cover apiCall.
There was a problem hiding this comment.
Done in 97e7799: added a test for the /logout retry.
Apple's sign-in servers answer 502/503/504 for a share of valid requests. Read-only calls (service key, olympus config, hashcash challenge) now retry up to 5 times. Sign-in POSTs are never retried.
Move the retry loop into TransientRetryPolicy (named attempts, delay and status codes) used by apiCall and the /logout request. The delay is injectable so tests do not sleep. Add a test for the /logout retry.
Noora 0.57.8 requires swift-log below 1.17.2, so the 1.17.2 bump (#167) made dependency resolution fail. 1.17.1 is the highest version both accept.
97e7799 to
f24390c
Compare
xcodeinstall authenticatenow retries when Apple's servers answer 502, 503 or 504.Right now about half of the requests to
idmsa.apple.comfail that way, so each run broke at a different step (502, 504, or a JSON error from an HTML error page).Read-only requests retry up to 5 times with a short pause: the service key lookup, the olympus config call and the hashcash challenge. Sign-in POSTs never retry.
Tests:
swift testpasses (207 existing plus 2 new forapiCall).