Repository navigation
fix(http): fail at once on a refused server certificate instead of retrying - #632
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b79bc7802
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…trying An expired, self-signed or wrong-host certificate was reported as a retryable network error, so a download retried it three times, about 15 seconds, before failing with "Network error occurred" and a cause chain that repeats itself. The certificate is refused the same way on every attempt. KtorHttpEngine now reads the refusal from JSSE, Conscrypt and OkHttp exceptions (JVM, Android) or NSURLErrorServerCertificate codes (iOS) and fails with a SourceError saying which: expired, not valid yet, revoked, for another host or not trusted. Metalink mirrors drop a mirror whose certificate is refused at once rather than backing off.
5b79bc7 to
92d0028
Compare
Problem
Downloading from a server whose certificate the platform refuses (expired, self-signed, issued for another host, unknown root) failed with a retryable
KetchError.Network. Every download retried it three times, about 15 seconds, before giving up:The certificate is the same on every attempt, so the retries only delay the failure. The apps then say "Connection lost" and suggest checking the connection, which doesn't help either.
Fix
KtorHttpEngineclassifies a refused certificate (certificateProblemOf, expect/actual) and fails the request with a non-retryableKetchError.SourceErrorsaying which problem it found:CertificateExpiredException,CertificateNotYetValidException,CertificateRevokedException, theCertPathValidatorExceptionreasons, OkHttp'sHostname … not verifiedand any otherCertificateException.NSURLErrorServerCertificate*codes.Networkerrors.MirrorPooldrops a mirror at once on such aSourceErrorinstead of backing off and retrying it five times.requestHeaders.After this change, against badssl.com:
The download now fails in about 1 s instead of 16 s, and the HEAD probe no longer falls back to a ranged GET.
Tests
CertificateProblemTest(jvmTest):HttpsServerwith a self-signed certificate (keytool): the engine fails at once with the detail, without retrying, and the server sees no request.MirrorPoolTest: a refused certificate drops the mirror, a network error keeps it. This test fails without the fix.expired,self-signed,wrong.hostanduntrusted-root.badssl.com, plusbadssl.comitself, which still downloads.