Repository navigation
fix(connections): stop reconnecting on TLS failures that retrying cannot fix - #3170
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Signed-off-by: Ngô Quốc Đạt <[email protected]>
Signed-off-by: Ngô Quốc Đạt <[email protected]>
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while fixing #3166 (#3168).
Root cause
The health monitor's reconnect loop (
DatabaseManager+Health.swift) stopped only on an authentication failure. Every other error returned.retry, and the loop retries forever with a 120-second ceiling. So a TLS failure that no amount of retrying can fix, such as a server that started requiring TLS, one that stopped accepting it, or a client certificate or key it rejects, was retried forever. From attempt 5 the window said "The connection stopped responding." and never named the reason.SSLHandshakeErroris not aPluginDriverError, and its text matches none of the auth phrases, so it never stopped the loop.A second defect sat underneath.
ClickHouseSSLClassifierfell through from its URLError switch to a message check for "hostname", so a DNS failure (URLError.cannotFindHost, "A server with the specified hostname could not be found.") was reported as a TLS hostname mismatch. Measured with a probe. Stopping on a hostname mismatch would have made every ClickHouse DNS blip after sleep or a VPN change stop the reconnect for good.What changed
ConnectionFailureClassifier.reconnectVerdict(for:)decides perSSLHandshakeErrorcase:serverRejectedPlaintext,serverRequiresPlaintext,clientCertRequired,clientKeyPassphraseRequired,clientKeyPassphraseIncorrect,clientKeyInvalid. These need an edit to the connection.untrustedCertificate,hostnameMismatch. A captive portal, a TLS-inspecting proxy or split-horizon DNS off the VPN produces exactly these, and the connection recovers once the network is right, so they must not stop the loop.cipherMismatch,unknown(drivers use them as catch-alls for resets during a restart), and any future case.SSLHandshakeError.formattedtext and Reconnect.ReconnectOutcome.retry(_:). The monitor hands the last attempt's failure to the attempt-5 threshold, which shows it in place of "The connection stopped responding." The on-demand verification path writes it too, and no longer overwrites a reason a stopped reconnect already recorded.ClickHouseSSLClassifier: once a URLError is found, its code decides (default: return nil). This is a body change only, so there is no ABI change.Behaviour change: PostgreSQL's "no pg_hba.conf entry … no encryption" is classified as
serverRejectedPlaintext, so it now stops the reconnect where it used to retry forever. That is intended: TLS off against a server that requires it is a setting only the user can change.The auth path gives the same message as before. Its status write is now fenced on the attempted driver as well.
Verification
verify.sh build: PASS.verify.sh test: 164/164 across 26 suites, includingHealthMonitorReconnectTests,ConnectionVerificationTests,ConnectionFailureClassifierTests, the seven classifier suites inPluginSSLClassifierTests.swift,ConnectionHealthMonitorAbortTests,ReconnectDegradationTests,ReconnectCredentialRecoveryTestsand the newConnectionHealthMonitorRetryTests. Each of the 22 new or changed tests was confirmed executed in the log. The reconnect tests drive aFakeMSSQLPluginwhose connect throws a chosen error, keyed by connection id so parallel suites cannot collide.verify.sh abiagainst the merge base: PluginKit ABI unchanged.swiftlint --stricton every changed file: 0 violations. Seven pre-existing violations in two touched test helpers were fixed while there.No UI test: the reconnect path is driven by the health monitor, which unit tests reach deterministically through the fake plugin, and a real TLS failure on reconnect cannot be staged deterministically in XCUITest.
Reviewed by the code-review skill's design critique before implementation (Codex is out of quota until 2026-09-29). The critique is what moved
untrustedCertificateandhostnameMismatchfrom stop to retry-with-reason.