Repository navigation
fix(client): fail fast on TLS certificate errors - #430
Conversation
There was a problem hiding this comment.
Verdict: 1 Low
Looks good overall, with one low-severity CI coverage gap. The certificate classifier finds the cause by walking the error chain, including errors nested inside io::Error. On native-tls it only matches text on native_tls::Error values. The new error messages report the current attempt's full source chain.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good, with one low concern. The certificate checks look correct: on rustls they match on the error type, on native-tls they match on message text, and only within TLS errors. Peer alerts, timeouts and refused connections still retry, and the tests cover both request types on both TLS backends.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good, with one low-severity note: the rustls and native-tls backends classify revocation-status errors differently. The error-chain walk handles reqwest's io::Error wrapping of TLS errors correctly. Tests cover both fail-fast and retry-preserving paths, and rustls/rcgen are already dev-dependencies, so the TLS tests compile under tls-native.
| #[cfg(feature = "tls-rustls")] | ||
| if matches!( | ||
| error.downcast_ref::<rustls::Error>(), | ||
| Some(rustls::Error::InvalidCertificate(_) | rustls::Error::NoCertificatesPresented) |
There was a problem hiding this comment.
🔵 Low — The rustls branch treats every rustls::Error::InvalidCertificate(_) as permanent. That includes CertificateError::UnknownRevocationStatus and ExpiredRevocationList, which are "revocation info isn't available" conditions. The native-tls branch deliberately keeps the equivalent SChannel codes retryable (CRYPT_E_NO_REVOCATION_CHECK, CRYPT_E_REVOCATION_OFFLINE), so the two backends now behave differently. Today this has no effect because the reqwest rustls config doesn't set up CRL checking, but it will matter if revocation checking is turned on later. Consider listing which CertificateError variants count as permanent (or excluding the revocation-status ones) so both backends follow the same policy.
There was a problem hiding this comment.
Verdict: 1 Medium
Looks solid overall, with one medium concern. The kernel Error.retryable flag now carries the per-request idempotency decision, not just whether the failure is permanent. That changes the flag for more errors than the PR and the updated NetworkError doc describe.
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Low · 1 Nit
Looks good. The fail-fast classification is narrowly scoped and well tested, and existing retry flags are preserved for other transport errors. Two low-severity notes: one test bypasses the kernel's own TLS client builder, and the Apple OSStatus parsing has never run against a real native-tls error on macOS.
Other findings
- ⚪ Nit — For
DnsHostnameMismatch, the test swapsclient.clientfor a plainreqwest::Client::builder()client with its own root cert. That skips the kernel's real TLS/client builder (HttpClientConfig.tls, proxy and timeout settings), so the case only exercises reqwest defaults plus the retry classifier. It does not check that a kernel-built client classifies hostname mismatches as permanent. This is acceptable for testing the classifier, but a short comment saying so would help. Alternatively, inject the resolver through the kernel builder if it supports that, so this case covers the same path as the others.
| if let Some(error) = error.downcast_ref::<native_tls::Error>() { | ||
| #[cfg(target_vendor = "apple")] | ||
| if let Some(permanent) = apple_certificate_verification_failure(&format!("{error:?}")) { | ||
| return permanent; |
There was a problem hiding this comment.
🔵 Low — The Apple path parses format!("{error:?}") on a native_tls::Error and expects it to begin with Error { code: . That depends on native-tls and security-framework both forwarding Debug without adding a wrapper such as Error(Error { .. }). The unit tests only feed hand-written strings, and the PR notes that no macOS runtime was available. If the format differs, the code silently falls back to matching English messages, and localized macOS errors will keep retrying. Consider a #[cfg(target_vendor = "apple")] test that builds a real native_tls::Error from a failed handshake against the local rcgen server. Or downcast/extract the OSStatus in a structured way if the native-tls version allows it.
There was a problem hiding this comment.
Verdict: 1 Medium
Looks solid overall: one medium concern. The rustls, OpenSSL and SChannel classification, error-chain preservation and CloudFetch short-circuit are well tested. The macOS OSStatus path, though, depends on a guessed Debug format that nothing has checked against the real wrapper type.
| // native-tls forwards security-framework's Debug, which retains OSStatus | ||
| // even when Display contains only a localized message. | ||
| let code = debug | ||
| .strip_prefix("Error { code: ")? |
There was a problem hiding this comment.
🟡 Medium — apple_certificate_verification_failure only matches when the whole {error:?} string begins with Error { code: . That is the format of security_framework::base::Error's hand-written Debug. On macOS, though, the value being formatted is a native_tls::Error, which forwards Debug to the backend's imp::Error. As far as I remember, native-tls's security_framework backend declares that as a newtype with #[derive(Debug)] (pub struct Error(base::Error)). If so, the real output is Error(Error { code: -67602, message: ... }), strip_prefix returns None, and classification drops back to the English-only marker list. The localized-macOS support this PR describes would then never kick in: a German or French host would treat an untrusted or mismatched certificate as retryable again.
The unit fixtures are hand-written bare base::Error strings, and the PR notes that no macOS runtime was available, so nothing has exercised the real formatting. I haven't checked this against the native-tls source, so please confirm the actual Debug output. A sturdier option is to look for the code: token anywhere in the string (e.g. debug.find("code: ")) rather than requiring it at the start. Better still, add a fixture taken from a real native_tls::Error produced on macOS.
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Low
Looks good. There is one low-severity inconsistency between the rustls and native-tls classification policies. The fail-fast logic is limited to certificate errors, the existing retryable flags stay the same for DNS, timeouts and redirects, and the CloudFetch short-circuit only fires for the new non-retryable NetworkError. Tests cover the changed behavior at the right tiers and on both TLS backends.
| #[cfg(feature = "tls-rustls")] | ||
| if matches!( | ||
| error.downcast_ref::<rustls::Error>(), | ||
| Some(rustls::Error::InvalidCertificate(_) | rustls::Error::NoCertificatesPresented) |
There was a problem hiding this comment.
🔵 Low — The rustls branch matches every rustls::Error::InvalidCertificate(_) variant. That includes CertificateError::UnknownRevocationStatus and CertificateError::Other(..), so both are classified as permanent and returned immediately with retryable=false. The native-tls branch takes the opposite position: it deliberately keeps revocation-availability failures retryable (CRYPT_E_REVOCATION_OFFLINE / CRYPT_E_NO_REVOCATION_CHECK are left out of the list and covered by negative tests). With today's default webpki verifier (no CRLs) this probably can't happen, but if a custom verifier or CRLs are ever configured, the two backends would disagree on the same condition. Consider excluding UnknownRevocationStatus explicitly, or documenting that the rustls policy is intentionally broader.
aakash-saravanan-db
left a comment
There was a problem hiding this comment.
LGTM. No blocking findings. Focused validation passed: 148 tests with native-tls, 144 with rustls, and the CloudFetch bounded-retry regression covering HTTP 403 and 500.
This review was generated with GitHub MCP.
Reject invalid server certificates after one attempt and include the underlying verification cause in errors, across native-tls, rustls, and CloudFetch.
retryable=trueretryable=falseValidated with full native tests, rustls client/CloudFetch tests, and fmt/clippy for both backends. TLS regressions check one connection, zero HTTP requests, and the certificate cause.
Limits: macOS runtime unavailable; Go/Python/Node/ODBC tripwires not rerun. Full rustls has the pre-existing
mtls_identity_is_forwarded_when_session_opensfailure.