-
-
Notifications
You must be signed in to change notification settings - Fork 297
fix: stop Oracle decode crashes and mislabeled MongoDB TLS errors (#483, #1418) #1723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ struct OracleError: Error { | |
| case notConnected | ||
| case connectionFailed | ||
| case queryFailed | ||
| case protocolError | ||
| case authVerifierUnsupported(flag: String) | ||
| case authVersionNotSupported | ||
| case authConnectionDropped | ||
|
|
@@ -264,11 +265,39 @@ final class OracleConnectionWrapper: @unchecked Sendable { | |
| return String(localized: "The Oracle server closed the connection during the login handshake.") | ||
| case .authVerifierUnsupported: | ||
| return String(localized: "This account uses a password verifier the database driver does not support.") | ||
| case .generic, .notConnected, .connectionFailed, .queryFailed: | ||
| case .generic, .notConnected, .connectionFailed, .queryFailed, .protocolError: | ||
| return serverDetail | ||
| } | ||
| } | ||
|
|
||
| private func mapQueryError(_ sqlError: OracleSQLError) -> OracleError { | ||
| guard Self.isChannelFatal(sqlError) else { | ||
| return OracleError(message: sqlError.serverInfo?.message ?? sqlError.description) | ||
| } | ||
| state.withLock { current in | ||
| current.isConnected = false | ||
| current.nioConnection = nil | ||
| } | ||
| osLogger.error("Oracle connection reset after fatal protocol error: \(sqlError.code.description)") | ||
| return OracleError( | ||
| message: String(localized: "The server sent an unexpected message and the connection was reset. Run the query again."), | ||
| category: .protocolError | ||
| ) | ||
| } | ||
|
|
||
| private static func isChannelFatal(_ error: OracleSQLError) -> Bool { | ||
| isChannelFatalCode(error.code.description) | ||
| } | ||
|
|
||
| static func isChannelFatalCode(_ codeDescription: String) -> Bool { | ||
| switch codeDescription { | ||
| case "connectionError", "messageDecodingFailure", "unexpectedBackendMessage": | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| func disconnect() { | ||
| let connection = state.withLock { current -> OracleNIO.OracleConnection? in | ||
| guard current.isConnected else { return nil } | ||
|
|
@@ -352,9 +381,8 @@ final class OracleConnectionWrapper: @unchecked Sendable { | |
| isTruncated: truncated | ||
| ) | ||
| } catch let sqlError as OracleSQLError { | ||
| let detail = sqlError.serverInfo?.message ?? sqlError.description | ||
| await queryGate.release() | ||
| throw OracleError(message: detail) | ||
| throw mapQueryError(sqlError) | ||
|
Comment on lines
384
to
+385
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a channel-fatal Useful? React with 👍 / 👎. |
||
| } catch let error as OracleError { | ||
| await queryGate.release() | ||
| throw error | ||
|
|
@@ -438,9 +466,8 @@ final class OracleConnectionWrapper: @unchecked Sendable { | |
| await queryGate.release() | ||
| continuation.finish() | ||
| } catch let sqlError as OracleSQLError { | ||
| let detail = sqlError.serverInfo?.message ?? sqlError.description | ||
| await queryGate.release() | ||
| throw OracleError(message: detail) | ||
| throw mapQueryError(sqlError) | ||
| } catch is CancellationError { | ||
| await queryGate.release() | ||
| throw CancellationError() | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import Foundation | ||
| import Testing | ||
|
|
||
| @testable import TablePro | ||
|
|
||
| @Suite("Oracle channel-fatal error classification") | ||
| struct OracleConnectionErrorTests { | ||
| @Test("Decode and connection failures are treated as channel-fatal") | ||
| func channelFatalCodes() { | ||
| #expect(OracleConnectionWrapper.isChannelFatalCode("connectionError")) | ||
| #expect(OracleConnectionWrapper.isChannelFatalCode("messageDecodingFailure")) | ||
| #expect(OracleConnectionWrapper.isChannelFatalCode("unexpectedBackendMessage")) | ||
| } | ||
|
|
||
| @Test("Server-side SQL errors keep the connection alive") | ||
| func nonFatalCodes() { | ||
| #expect(!OracleConnectionWrapper.isChannelFatalCode("server")) | ||
| #expect(!OracleConnectionWrapper.isChannelFatalCode("statementCancelled")) | ||
| #expect(!OracleConnectionWrapper.isChannelFatalCode("malformedStatement")) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this narrowed signature list, a genuine libmongoc message such as
TLS handshake failed: bad cipher(the case the previous test covered) no longer matches and then falls through to the generic handshake branch as.unknown. Users in that cipher-negotiation failure case lose the cipher/protocol recovery guidance, so include the bad-cipher wording in the mismatch signatures rather than treating it as unknown.Useful? React with 👍 / 👎.