diff --git a/apple/Packages/TableProOracle/Package.resolved b/apple/Packages/TableProOracle/Package.resolved index e08958da1a..4a01c396eb 100644 --- a/apple/Packages/TableProOracle/Package.resolved +++ b/apple/Packages/TableProOracle/Package.resolved @@ -15,7 +15,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/TableProApp/oracle-nio", "state" : { - "revision" : "045a44674e9f9da3904e0f2b87995490a7cc88e4" + "revision" : "28d9d83b9b88440598862f04e43ca527dcac1d7d" } }, { diff --git a/apple/Packages/TableProOracle/Package.swift b/apple/Packages/TableProOracle/Package.swift index 36e073ceb7..44ba3cec81 100644 --- a/apple/Packages/TableProOracle/Package.swift +++ b/apple/Packages/TableProOracle/Package.swift @@ -14,7 +14,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/TableProApp/oracle-nio", - revision: "045a44674e9f9da3904e0f2b87995490a7cc88e4" + revision: "28d9d83b9b88440598862f04e43ca527dcac1d7d" ), .package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"), .package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.29.0"), diff --git a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleConnectFailureMapping.swift b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleConnectFailureMapping.swift new file mode 100644 index 0000000000..2cb5b81d50 --- /dev/null +++ b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleConnectFailureMapping.swift @@ -0,0 +1,121 @@ +import Foundation +import OracleNIO + +// What a failed connect says to the user. The driver's error structs are not for display, as the query path's +// `mapQueryError` says: they can carry this device's host name and OS user, or a login packet in hex. +enum OracleConnectFailureMapping { + static func connectError( + code: String, + underlying: (any Error)?, + serverMessage: String?, + phase: String?, + nativeNetworkEncryptionEnabled: Bool + ) -> OracleCoreError { + let detail = failureDetail(code: code, underlying: underlying, serverMessage: serverMessage) + // BoringSSL's text is what tells an untrusted certificate from a cipher mismatch, and a TLS failure at a + // redirect's target sits one level further down. + let nested = (underlying as? OracleRedirectError)?.underlying + for candidate in [detail] + [underlying, nested].compactMap({ tlsText($0) }) { + if let kind = OracleSSLClassifier.classifyTLSFailure(candidate) { + return .tlsHandshakeFailed(kind: kind, serverMessage: candidate) + } + } + if let redirect = underlying as? OracleRedirectError { + return redirectError(redirect) + } + if let underlying, OracleTransportFailure.isConnectionRefused(underlying) { + return .connectionRefused + } + let failure = OracleConnectErrorClassifier.classify(code) + if case .loginHandshakeTimedOut = failure { + return .loginHandshakeStalled(phase: phase) + } + if case .advancedNegotiationRequired = failure { + return .nativeEncryptionRequired + } + if OracleConnectErrorClassifier.isLikelyNativeEncryptionFailure( + failure: failure, + nativeNetworkEncryptionEnabled: nativeNetworkEncryptionEnabled, + timedOut: false + ) { + return .nativeEncryptionFailed(detail: detail) + } + switch failure { + case .verifierUnsupported(let flag): + return .authVerifierUnsupported(flag: flag) + case .versionNotSupported: + return .authVersionNotSupported + case .connectionDropped: + return .authConnectionDropped(phase: phase) + case .advancedNegotiationFailed: + return .nativeEncryptionFailed(detail: detail) + case .advancedNegotiationRequired: + return .nativeEncryptionRequired + case .loginHandshakeTimedOut: + return .loginHandshakeStalled(phase: phase) + case .connectionFailed: + return .connectionFailed(detail) + } + } + + // Only NIOSSL's own errors are read for TLS words. Any other description can hold what a listener sent, such as a + // REFUSE that echoes this device's host name and OS user next to an ORA-29024. + static func tlsText(_ error: (any Error)?) -> String? { + guard let error, String(reflecting: type(of: error)).hasPrefix("NIOSSL.") else { return nil } + return String(describing: error) + } + + static func failureDetail(code: String, underlying: (any Error)?, serverMessage: String?) -> String { + if let refused = underlying as? OracleListenerRefusedError { + return OracleListenerRefusal.detail(code: refused.code) + } + if let serverMessage { + return serverMessage + } + if let underlying { + if let transport = OracleTransportFailure.detail(underlying) { + return transport + } + // The negotiation's reason is a plain sentence, the one underlying error that is. + if OracleConnectErrorClassifier.classify(code) == .advancedNegotiationFailed { + return String(describing: underlying) + } + } + return String(format: OracleCoreError.driverErrorFormat, code) + } + + static func transportError(_ error: any Error) -> OracleCoreError { + if OracleTransportFailure.isConnectionRefused(error) { + return .connectionRefused + } + let detail = OracleTransportFailure.detail(error) + ?? String(format: OracleCoreError.driverErrorFormat, String(describing: type(of: error))) + return .connectionFailed(detail) + } + + static func redirectError(_ redirect: OracleRedirectError) -> OracleCoreError { + let target = redirect.host.map { host -> String in + let shown = host.contains(":") ? "[\(host)]" : host + return redirect.port.map { "\(shown):\($0)" } ?? shown + } + switch redirect.reason { + case .notFollowed: + // Following is turned off only when the dial is a tunnel's forward. + return .listenerRedirectFailed(.throughTunnel, target: target) + case .unreadable: + return .listenerRedirectFailed(.unreadable, target: nil) + case .transportMismatch: + return .listenerRedirectFailed(.needsTLS, target: target) + case .tooManyRedirects: + return .listenerRedirectFailed(.tooManyRedirects, target: target) + case .targetUnreachable: + let detail = redirect.underlying.flatMap(OracleTransportFailure.detail) + return .listenerRedirectFailed(.unreachable(detail: detail), target: target) + case .targetRefused: + let refusal = redirect.underlying as? OracleListenerRefusedError + return .listenerRedirectFailed( + .refused(detail: OracleListenerRefusal.detail(code: refusal?.code)), target: target + ) + } + } +} diff --git a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleConnectionOptions.swift b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleConnectionOptions.swift index 7aae9c7284..f25020e7b3 100644 --- a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleConnectionOptions.swift +++ b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleConnectionOptions.swift @@ -55,6 +55,8 @@ public struct OracleConnectionOptions: Sendable, Equatable { public var tls: OracleTLSDescription public var networkEncryption: NetworkEncryption public var loginTimeoutSeconds: Double + // Off when the dial is a tunnel's forward: the address a listener redirects to is one only the far side reaches. + public var followsListenerRedirects: Bool public init( host: String, @@ -68,7 +70,8 @@ public struct OracleConnectionOptions: Sendable, Equatable { role: Role = .normal, tls: OracleTLSDescription = OracleTLSDescription(), networkEncryption: NetworkEncryption = .accepted, - loginTimeoutSeconds: Double = OracleConnectionOptions.defaultLoginTimeoutSeconds + loginTimeoutSeconds: Double = OracleConnectionOptions.defaultLoginTimeoutSeconds, + followsListenerRedirects: Bool = true ) { self.host = host self.port = port @@ -82,6 +85,7 @@ public struct OracleConnectionOptions: Sendable, Equatable { self.tls = tls self.networkEncryption = networkEncryption self.loginTimeoutSeconds = loginTimeoutSeconds + self.followsListenerRedirects = followsListenerRedirects } public var identifier: String { diff --git a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreConnection.swift b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreConnection.swift index f055e7d5db..f5b7e08acb 100644 --- a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreConnection.swift +++ b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreConnection.swift @@ -157,6 +157,7 @@ public final class OracleCoreConnection: @unchecked Sendable { ) configuration.mode = authenticationMode(for: options.role) configuration.nativeNetworkEncryption = encryptionLevel(for: options.networkEncryption) + configuration.followsListenerRedirects = options.followsListenerRedirects // The driver owns the channel, so it is the only thing that can end a login the // server has stopped answering, and it names the handshake phase when it does. // The wrapper in connect() stays a grace period behind it as a backstop for a driver @@ -248,10 +249,10 @@ public final class OracleCoreConnection: @unchecked Sendable { } catch { let detail = String(describing: error) osLogger.error("Oracle connection failed: \(String(describing: type(of: error)), privacy: .public) \(detail, privacy: .private)") - if let kind = OracleSSLClassifier.classifyTLSFailure(detail) { - throw OracleCoreError.tlsHandshakeFailed(kind: kind, serverMessage: detail) + if let tls = OracleConnectFailureMapping.tlsText(error), let kind = OracleSSLClassifier.classifyTLSFailure(tls) { + throw OracleCoreError.tlsHandshakeFailed(kind: kind, serverMessage: tls) } - throw OracleCoreError.connectionFailed(detail) + throw OracleConnectFailureMapping.transportError(error) } } @@ -334,58 +335,19 @@ public final class OracleCoreConnection: @unchecked Sendable { } private func connectError(from sqlError: OracleSQLError) -> OracleCoreError { - let detail = Self.connectFailureDetail(sqlError) let phase = sqlError.handshakePhase let code = sqlError.code.description + let underlying = sqlError.underlying.map { String(describing: $0) } ?? "" osLogger.error( - "Oracle connection failed at phase \(phase ?? "unknown", privacy: .public) (\(code, privacy: .public))" + "Oracle connection failed at phase \(phase ?? "unknown", privacy: .public) (\(code, privacy: .public)): \(underlying, privacy: .private)" + ) + return OracleConnectFailureMapping.connectError( + code: code, + underlying: sqlError.underlying, + serverMessage: sqlError.serverInfo?.message, + phase: phase, + nativeNetworkEncryptionEnabled: options.networkEncryption != .rejected ) - if let kind = OracleSSLClassifier.classifyTLSFailure(detail) { - return .tlsHandshakeFailed(kind: kind, serverMessage: detail) - } - let failure = OracleConnectErrorClassifier.classify(sqlError.code.description) - if case .loginHandshakeTimedOut = failure { - return .loginHandshakeStalled(phase: phase) - } - if case .advancedNegotiationRequired = failure { - return .nativeEncryptionRequired - } - if OracleConnectErrorClassifier.isLikelyNativeEncryptionFailure( - failure: failure, - nativeNetworkEncryptionEnabled: options.networkEncryption != .rejected, - timedOut: false - ) { - return .nativeEncryptionFailed(detail: detail) - } - switch failure { - case .verifierUnsupported(let flag): - return .authVerifierUnsupported(flag: flag) - case .versionNotSupported: - return .authVersionNotSupported - case .connectionDropped: - return .authConnectionDropped(phase: phase) - case .advancedNegotiationFailed: - return .nativeEncryptionFailed(detail: detail) - case .advancedNegotiationRequired: - return .nativeEncryptionRequired - case .loginHandshakeTimedOut: - return .loginHandshakeStalled(phase: phase) - case .connectionFailed: - return .connectionFailed(detail) - } - } - - private static func connectFailureDetail(_ error: OracleSQLError) -> String { - if let refused = error.underlying as? OracleListenerRefusedError { - return OracleListenerRefusal.detail(code: refused.code) - } - if let serverMessage = error.serverInfo?.message { - return serverMessage - } - if let underlying = error.underlying { - return String(describing: underlying) - } - return String(format: OracleCoreError.driverErrorFormat, error.code.description) } public func disconnect(reason: OracleDisconnectReason = .userRequested) { diff --git a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreError.swift b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreError.swift index 7f0fe98467..041d52287a 100644 --- a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreError.swift +++ b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleCoreError.swift @@ -13,6 +13,15 @@ public enum OracleCertificateField: Sendable, Equatable { case clientKey } +public enum OracleRedirectFailure: Sendable, Equatable { + case throughTunnel + case unreadable + case needsTLS + case tooManyRedirects + case unreachable(detail: String?) + case refused(detail: String) +} + public enum OracleCoreError: LocalizedError, Sendable, Equatable { case notConnected case connectionFailed(String) @@ -34,6 +43,8 @@ public enum OracleCoreError: LocalizedError, Sendable, Equatable { case certificateUnavailable(field: OracleCertificateField, path: String) case certificateAuthorityRequired case verifyIdentityNeedsHostName(address: String) + case listenerRedirectFailed(OracleRedirectFailure, target: String?) + case connectionRefused public var errorDescription: String? { switch self { @@ -88,6 +99,10 @@ public enum OracleCoreError: LocalizedError, Sendable, Equatable { return String(format: Self.certificateUnavailableFormat(for: field), path) case .certificateAuthorityRequired: return String(localized: "Verify CA needs a CA certificate. Choose the CA certificate that signed the server's certificate.") + case .listenerRedirectFailed(let failure, let target): + return Self.redirectMessage(failure, target: target) + case .connectionRefused: + return String(localized: "The server refused the connection. Check the host and port, and that the Oracle listener is running.") case .verifyIdentityNeedsHostName(let address): return String( format: String(localized: """ @@ -99,6 +114,56 @@ public enum OracleCoreError: LocalizedError, Sendable, Equatable { } } + private static func redirectMessage(_ failure: OracleRedirectFailure, target: String?) -> String { + let unreadable = String(localized: "The Oracle listener redirected the connection to an address TablePro could not read.") + guard let target else { + if case .tooManyRedirects = failure { + return String(localized: "The Oracle listeners redirected the connection too many times.") + } + return unreadable + } + switch failure { + case .throughTunnel: + return String( + format: String(localized: """ + The Oracle listener redirected the connection to %@, which the tunnel does not forward. Enter that \ + host and port as this connection's host and port so the tunnel reaches them. + """), + target + ) + case .unreadable: + return unreadable + case .needsTLS: + return String( + format: String(localized: "The Oracle listener redirected the connection to %@, which expects TLS. Set an SSL mode for this connection."), + target + ) + case .tooManyRedirects: + return String( + format: String(localized: "The Oracle listeners redirected the connection too many times. The last address was %@."), + target + ) + case .refused(let detail): + return String( + format: String(localized: "The Oracle listener redirected the connection to %1$@, and the listener there refused it. %2$@"), + target, + detail + ) + case .unreachable(let detail): + guard let detail else { + return String( + format: String(localized: "The Oracle listener redirected the connection to %@, which could not be reached."), + target + ) + } + return String( + format: String(localized: "The Oracle listener redirected the connection to %1$@, which could not be reached (%2$@)."), + target, + detail + ) + } + } + /// What a driver failure with no server message behind it says to the user. OracleNIO's own /// error description is a struct dump it documents as unfit to show, so the code's name is /// what carries across. diff --git a/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleTransportFailure.swift b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleTransportFailure.swift new file mode 100644 index 0000000000..2ac2a37e9b --- /dev/null +++ b/apple/Packages/TableProOracle/Sources/TableProOracleCore/OracleTransportFailure.swift @@ -0,0 +1,38 @@ +import Foundation +import Network +import NIOCore + +// A connect that fails below the TNS exchange throws Network.framework's or SwiftNIO's own error, whose description is +// a struct dump. These are the cases a user can act on, in words. +public enum OracleTransportFailure { + public static func isConnectionRefused(_ error: any Error) -> Bool { + posixCode(of: error) == ECONNREFUSED + } + + public static func detail(_ error: any Error) -> String? { + if case .connectTimeout(let amount) = error as? ChannelError { + let seconds = max(1, Int((Double(amount.nanoseconds) / 1_000_000_000).rounded())) + return String(format: String(localized: "no answer within %lld seconds"), seconds) + } + if let nwError = error as? NWError, case .dns = nwError { + return String(localized: "the host name could not be resolved") + } + if let code = posixCode(of: error), let text = strerror(code) { + return String(cString: text) + } + return nil + } + + private static func posixCode(of error: any Error) -> Int32? { + if let nwError = error as? NWError, case .posix(let code) = nwError { + return code.rawValue + } + if let ioError = error as? IOError { + return ioError.errnoCode + } + if let posixError = error as? POSIXError { + return posixError.code.rawValue + } + return nil + } +} diff --git a/apple/Packages/TableProOracle/Tests/TableProOracleCoreTests/OracleConnectFailureMappingTests.swift b/apple/Packages/TableProOracle/Tests/TableProOracleCoreTests/OracleConnectFailureMappingTests.swift new file mode 100644 index 0000000000..517d8c50e4 --- /dev/null +++ b/apple/Packages/TableProOracle/Tests/TableProOracleCoreTests/OracleConnectFailureMappingTests.swift @@ -0,0 +1,167 @@ +import Foundation +import Network +import NIOCore +import NIOSSL +import OracleNIO +@testable import TableProOracleCore +import Testing + +struct OracleConnectFailureMappingTests { + @Test func aRedirectNamesItsTargetForEachReason() { + #expect( + OracleConnectFailureMapping.redirectError(OracleRedirectError(reason: .notFollowed, host: "10.0.0.12", port: 1_521)) + == .listenerRedirectFailed(.throughTunnel, target: "10.0.0.12:1521") + ) + #expect( + OracleConnectFailureMapping.redirectError(OracleRedirectError(reason: .transportMismatch, host: "node1", port: 2_484)) + == .listenerRedirectFailed(.needsTLS, target: "node1:2484") + ) + #expect( + OracleConnectFailureMapping.redirectError(OracleRedirectError(reason: .tooManyRedirects, host: "node2", port: 1_521)) + == .listenerRedirectFailed(.tooManyRedirects, target: "node2:1521") + ) + #expect( + OracleConnectFailureMapping.redirectError(OracleRedirectError(reason: .unreadable, host: nil, port: nil)) + == .listenerRedirectFailed(.unreadable, target: nil) + ) + #expect( + OracleConnectFailureMapping.redirectError(OracleRedirectError(reason: .notFollowed, host: "fe80::1", port: 1_521)) + == .listenerRedirectFailed(.throughTunnel, target: "[fe80::1]:1521") + ) + } + + @Test func anUnreachableTargetSaysWhy() { + let error = OracleRedirectError( + reason: .targetUnreachable, host: "node1-vip", port: 1_521, underlying: NWError.posix(.ECONNREFUSED) + ) + #expect( + OracleConnectFailureMapping.redirectError(error) + == .listenerRedirectFailed(.unreachable(detail: "Connection refused"), target: "node1-vip:1521") + ) + } + + @Test func aRefusalAtTheTargetSaysWhereAndWhy() { + let error = OracleRedirectError( + reason: .targetRefused, host: "node1", port: 1_521, + underlying: OracleListenerRefusedError(code: 12_514, message: "(DESCRIPTION=(ERR=12514))") + ) + #expect( + OracleConnectFailureMapping.redirectError(error) + == .listenerRedirectFailed(.refused(detail: OracleListenerRefusal.detail(code: 12_514)), target: "node1:1521") + ) + } + + private let certificateFailure = NIOSSLError.handshakeFailed(.wantCertificateVerify) + + @Test func aTLSFailureIsStillReadFromTheUnderlyingError() { + let text = String(describing: certificateFailure) + let direct = OracleConnectFailureMapping.connectError( + code: "connectionError", underlying: certificateFailure, serverMessage: nil, phase: "connect", + nativeNetworkEncryptionEnabled: true + ) + #expect(direct == .tlsHandshakeFailed(kind: .untrustedCertificate, serverMessage: text)) + let atTheTarget = OracleConnectFailureMapping.connectError( + code: "connectionError", + underlying: OracleRedirectError( + reason: .targetUnreachable, host: "node1", port: 2_484, underlying: certificateFailure + ), + serverMessage: nil, phase: "connect", nativeNetworkEncryptionEnabled: true + ) + #expect(atTheTarget == .tlsHandshakeFailed(kind: .untrustedCertificate, serverMessage: text)) + } + + // A listener's REFUSE text is the listener's to write, and it echoes the client's CID. + @Test func aCraftedRefusalCannotSurfaceThroughTheTLSCheck() { + let refusal = OracleListenerRefusedError( + code: 12_514, + message: "(DESCRIPTION=(ERR=12514)(CID=(HOST=dats-mac)(USER=dat))) ORA-29024 certificate verify untrusted" + ) + let expected = OracleCoreError.connectionFailed(OracleListenerRefusal.detail(code: 12_514)) + #expect( + OracleConnectFailureMapping.connectError( + code: "connectionError", underlying: refusal, serverMessage: nil, phase: "connect", + nativeNetworkEncryptionEnabled: true + ) == expected + ) + let atTheTarget = OracleConnectFailureMapping.connectError( + code: "connectionError", + underlying: OracleRedirectError(reason: .targetRefused, host: "node1", port: 1_521, underlying: refusal), + serverMessage: nil, phase: "connect", nativeNetworkEncryptionEnabled: true + ) + #expect(!(atTheTarget.errorDescription ?? "").contains("USER=dat")) + #expect(!(atTheTarget.errorDescription ?? "").contains("dats-mac")) + } + + private struct LoginPacketDump: Error { + var payload = "AUTH_SESSKEY 0011223344" + } + + @Test func aDriverStructNeverReachesTheMessage() { + let error = OracleConnectFailureMapping.connectError( + code: "missingParameter", underlying: LoginPacketDump(), serverMessage: nil, phase: "authentication", + nativeNetworkEncryptionEnabled: true + ) + #expect(error == .connectionFailed(String(format: OracleCoreError.driverErrorFormat, "missingParameter"))) + } + + @Test func aRedirectTheDriverDidNotFollowIsNotAStructDump() { + let error = OracleConnectFailureMapping.connectError( + code: "connectionError", + underlying: OracleRedirectError(reason: .notFollowed, host: "10.0.0.12", port: 1_521), + serverMessage: nil, phase: "connect", nativeNetworkEncryptionEnabled: true + ) + #expect(error == .listenerRedirectFailed(.throughTunnel, target: "10.0.0.12:1521")) + #expect(!(error.errorDescription ?? "").contains("OracleRedirectError")) + } + + @Test func aResetDuringTheHandshakeReadsAsText() { + let error = OracleConnectFailureMapping.connectError( + code: "connectionError", underlying: NWError.posix(.ECONNRESET), serverMessage: nil, phase: "connect", + nativeNetworkEncryptionEnabled: false + ) + #expect(error == .connectionFailed("Connection reset by peer")) + } + + @Test func aRefusedPortIsSaidInWords() { + #expect(OracleConnectFailureMapping.transportError(NWError.posix(.ECONNREFUSED)) == .connectionRefused) + #expect(OracleConnectFailureMapping.transportError(IOError(errnoCode: ECONNREFUSED, reason: "connect")) == .connectionRefused) + } + + @Test func otherTransportFailuresReadAsText() { + #expect( + OracleConnectFailureMapping.transportError(ChannelError.connectTimeout(.seconds(10))) + == .connectionFailed("no answer within 10 seconds") + ) + #expect( + OracleConnectFailureMapping.transportError(NWError.posix(.EHOSTUNREACH)) == .connectionFailed("No route to host") + ) + #expect( + OracleConnectFailureMapping.transportError(NWError.dns(-65_554)) + == .connectionFailed("the host name could not be resolved") + ) + } + + private struct SomethingElse: Error { + var secret = "AUTH_SESSKEY" + } + + @Test func anUnknownFailureNamesItsTypeAndNothingInside() { + guard case .connectionFailed(let detail) = OracleConnectFailureMapping.transportError(SomethingElse()) else { + Issue.record("expected connectionFailed") + return + } + #expect(detail.contains("SomethingElse"), "\(detail)") + #expect(!detail.contains("AUTH_SESSKEY"), "\(detail)") + } + + @Test func theConfigurationCarriesWhetherToFollowRedirects() throws { + let direct = try OracleCoreConnection.configuration(for: OracleConnectionOptions( + host: "scan.example.com", user: "scott", password: "tiger" + )) + #expect(direct.followsListenerRedirects) + let tunneled = try OracleCoreConnection.configuration(for: OracleConnectionOptions( + host: "127.0.0.1", user: "scott", password: "tiger", followsListenerRedirects: false + )) + #expect(!tunneled.followsListenerRedirects) + } +} diff --git a/apple/Packages/TableProOracle/Tests/TableProOracleCoreTests/OracleCoreErrorMessageTests.swift b/apple/Packages/TableProOracle/Tests/TableProOracleCoreTests/OracleCoreErrorMessageTests.swift index bb39f0277e..dce020dc01 100644 --- a/apple/Packages/TableProOracle/Tests/TableProOracleCoreTests/OracleCoreErrorMessageTests.swift +++ b/apple/Packages/TableProOracle/Tests/TableProOracleCoreTests/OracleCoreErrorMessageTests.swift @@ -25,7 +25,16 @@ struct OracleCoreErrorMessageTests { .nativeEncryptionRequired, .tlsHandshakeFailed(kind: .cipherMismatch, serverMessage: "ORA-29024"), .certificateUnavailable(field: .clientKey, path: "/tmp/key.pem"), - .certificateAuthorityRequired + .certificateAuthorityRequired, + .listenerRedirectFailed(.throughTunnel, target: "10.0.0.12:1521"), + .listenerRedirectFailed(.unreadable, target: nil), + .listenerRedirectFailed(.needsTLS, target: "node1:2484"), + .listenerRedirectFailed(.tooManyRedirects, target: "node2:1521"), + .listenerRedirectFailed(.tooManyRedirects, target: nil), + .listenerRedirectFailed(.unreachable(detail: "Connection refused"), target: "node1-vip:1521"), + .listenerRedirectFailed(.unreachable(detail: nil), target: "node1-vip:1521"), + .listenerRedirectFailed(.refused(detail: "The listener does not know the requested service name (ORA-12514)."), target: "node1:1521"), + .connectionRefused ] @Test func testNoMessageLeaksTheDriversOwnErrorStruct() { @@ -33,6 +42,7 @@ struct OracleCoreErrorMessageTests { let message = error.errorDescription ?? "" #expect(!(message.contains("OracleSQLError(")), "\(message)") #expect(!message.contains("triggeredFromRequestInFile"), "\(message)") + #expect(!message.contains("OracleRedirectError"), "\(message)") #expect(!message.isEmpty) } } @@ -49,6 +59,22 @@ struct OracleCoreErrorMessageTests { #expect(!message.localizedCaseInsensitiveContains("tab"), "\(message)") } + // Under a tunnel the target is the one fact the user needs: it is the host to enter instead. + @Test func testEveryRedirectFailureNamesWhereTheListenerSentTheConnection() { + let failures: [OracleRedirectFailure] = [ + .throughTunnel, .needsTLS, .tooManyRedirects, .unreachable(detail: "Connection refused"), .unreachable(detail: nil), + .refused(detail: "ORA-12514") + ] + for failure in failures { + let message = OracleCoreError.listenerRedirectFailed(failure, target: "node1-vip:1521").errorDescription ?? "" + #expect(message.contains("node1-vip:1521"), "\(message)") + } + let unreachable = OracleCoreError.listenerRedirectFailed( + .unreachable(detail: "Connection refused"), target: "node1-vip:1521" + ).errorDescription ?? "" + #expect(unreachable.contains("Connection refused"), "\(unreachable)") + } + @Test func testADriverErrorWithNoServerMessageNamesItsCode() { let message = String(format: OracleCoreError.driverErrorFormat, "malformedStatement") #expect(message.contains("malformedStatement"), "\(message)") diff --git a/apple/Plugins/OracleDriverPlugin/OraclePlugin+Diagnostics.swift b/apple/Plugins/OracleDriverPlugin/OraclePlugin+Diagnostics.swift index 970869e057..b3739e9ec1 100644 --- a/apple/Plugins/OracleDriverPlugin/OraclePlugin+Diagnostics.swift +++ b/apple/Plugins/OracleDriverPlugin/OraclePlugin+Diagnostics.swift @@ -125,9 +125,43 @@ extension OraclePlugin: PluginDiagnosticProvider { ], supportURL: issuesURL ) + case .listenerRedirectFailed(let failure, let target): + return PluginDiagnostic( + title: String(localized: "Listener Redirect Not Followed"), + message: message, + suggestedActions: Self.redirectActions(failure), + diagnosticInfo: target.map { [DiagnosticEntry(label: String(localized: "Redirect target"), value: $0)] } ?? [], + supportURL: issuesURL + ) case .notConnected, .connectionFailed, .queryFailed, .cancelled, .connectTimedOut, .tlsHandshakeFailed, - .transactionLost, .certificateAuthorityRequired, .verifyIdentityNeedsHostName: + .transactionLost, .certificateAuthorityRequired, .verifyIdentityNeedsHostName, .connectionRefused: return nil } } + + private static func redirectActions(_ failure: OracleRedirectFailure) -> [String] { + switch failure { + case .throughTunnel: + return [ + String(localized: "Enter the host and port of the redirect target below as this connection's host and port, and keep the tunnel."), + String(localized: "Or connect without the tunnel if this device reaches the redirect target directly.") + ] + case .unreachable: + return [ + String(localized: "Check that this device can resolve and reach the redirect target below. RAC node addresses often resolve only on the server's network."), + String(localized: "Ask the DBA whether the listener can name an address clients reach, or connect to that address directly.") + ] + case .refused: + return [ + String(localized: "Ask the DBA whether the service is registered with the listener at the redirect target below."), + String(localized: "ORA-12516 there can mean that listener tried to redirect the connection again. Ask the DBA to check the listener settings.") + ] + case .needsTLS: + return [String(localized: "Set an SSL mode in the connection's SSL settings so it connects over TCPS.")] + case .tooManyRedirects: + return [String(localized: "Ask the DBA to check the LOCAL_LISTENER and REMOTE_LISTENER settings, which may point the listeners at each other.")] + case .unreadable: + return [String(localized: "File an issue with your Oracle version and how the listener is set up.")] + } + } } diff --git a/apple/Plugins/OracleDriverPlugin/OraclePlugin.swift b/apple/Plugins/OracleDriverPlugin/OraclePlugin.swift index 7217daf2cc..3890fcf371 100644 --- a/apple/Plugins/OracleDriverPlugin/OraclePlugin.swift +++ b/apple/Plugins/OracleDriverPlugin/OraclePlugin.swift @@ -255,7 +255,8 @@ nonisolated final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sen role: OracleConnectionOptions.role(from: config.additionalFields), tls: config.ssl.oracleTLSDescription(serverName: config.tunneledServerName), networkEncryption: OracleConnectionOptions.networkEncryption(from: config.additionalFields), - loginTimeoutSeconds: OracleConnectionOptions.loginTimeoutSeconds(from: config.additionalFields) + loginTimeoutSeconds: OracleConnectionOptions.loginTimeoutSeconds(from: config.additionalFields), + followsListenerRedirects: config.tunneledServerName == nil ) let deadline = OracleConnectDeadline(seconds: options.loginTimeoutSeconds) let connection = OracleCoreConnection(options: options) diff --git a/apple/TablePro.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/apple/TablePro.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index eac19468f1..9f3f15bdb5 100644 --- a/apple/TablePro.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/apple/TablePro.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -24,7 +24,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/TableProApp/oracle-nio", "state" : { - "revision" : "045a44674e9f9da3904e0f2b87995490a7cc88e4" + "revision" : "28d9d83b9b88440598862f04e43ca527dcac1d7d" } }, { diff --git a/apple/TablePro/Resources/Localizable.xcstrings b/apple/TablePro/Resources/Localizable.xcstrings index 399a3e85c5..b603489d68 100644 --- a/apple/TablePro/Resources/Localizable.xcstrings +++ b/apple/TablePro/Resources/Localizable.xcstrings @@ -32912,6 +32912,18 @@ } } }, + "Ask the DBA to check the LOCAL_LISTENER and REMOTE_LISTENER settings, which may point the listeners at each other." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "Ask the DBA whether the listener can name an address clients reach, or connect to that address directly." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "Ask the DBA whether the service is registered with the listener at the redirect target below." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "Ask the DBA which encryption and checksum algorithms the server requires. The driver supports AES with a SHA-2 checksum." : { "extractionState" : "manual", "generatesSymbol" : false, @@ -43259,6 +43271,10 @@ } } }, + "Check that this device can resolve and reach the redirect target below. RAC node addresses often resolve only on the server's network." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "Check the certificate paths in the connection's SSL settings." : { "extractionState" : "manual", "generatesSymbol" : false, @@ -83649,6 +83665,10 @@ }, "Enter the file's path on the server." : { + }, + "Enter the host and port of the redirect target below as this connection's host and port, and keep the tunnel." : { + "extractionState" : "manual", + "generatesSymbol" : false }, "Enter the Key Passphrase in the connection's SSL/TLS settings." : { "extractionState" : "manual", @@ -93034,6 +93054,10 @@ } } }, + "File an issue with your Oracle version and how the listener is set up." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "File an issue with your Oracle version and the details below so the driver can add support." : { "extractionState" : "manual", "generatesSymbol" : false, @@ -119853,6 +119877,10 @@ }, "LISTEN registrations" : { + }, + "Listener Redirect Not Followed" : { + "extractionState" : "manual", + "generatesSymbol" : false }, "Listens on all interfaces (0.0.0.0), reachable from your local network." : { "localizations" : { @@ -132383,6 +132411,10 @@ }, "No analyze recorded in the server's statistics, and this user cannot read the table's statistics to confirm it." : { + }, + "no answer within %lld seconds" : { + "extractionState" : "manual", + "generatesSymbol" : false }, "No approved connections. A connection a client may reach without asking again appears here." : { "localizations" : { @@ -148339,6 +148371,14 @@ "extractionState" : "manual", "generatesSymbol" : false }, + "Or connect without the tunnel if this device reaches the redirect target directly." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "ORA-12516 there can mean that listener tried to redirect the connection again. Ask the DBA to check the listener settings." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "Oracle" : { "extractionState" : "stale", "localizations" : { @@ -165086,6 +165126,10 @@ } } }, + "Redirect target" : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "Redis" : { "extractionState" : "stale", "localizations" : { @@ -186944,6 +186988,10 @@ } } }, + "Set an SSL mode in the connection's SSL settings so it connects over TCPS." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "Set as Active" : { "localizations" : { "fr" : { @@ -215586,6 +215634,10 @@ } } }, + "the host name could not be resolved" : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "The icon and color mark this connection in the connection list and its window." : { }, @@ -217286,6 +217338,30 @@ } } }, + "The Oracle listener redirected the connection to %@, which could not be reached." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %@, which expects TLS. Set an SSL mode for this connection." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %@, which the tunnel does not forward. Enter that host and port as this connection's host and port so the tunnel reaches them." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %1$@, and the listener there refused it. %2$@" : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %1$@, which could not be reached (%2$@)." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to an address TablePro could not read." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "The Oracle listener refused the connection (ORA-%ld)." : { "extractionState" : "manual", "generatesSymbol" : false, @@ -217370,6 +217446,14 @@ } } }, + "The Oracle listeners redirected the connection too many times." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listeners redirected the connection too many times. The last address was %@." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "The Oracle server accepted the connection but stopped answering during the login." : { "extractionState" : "manual", "generatesSymbol" : false, @@ -220169,6 +220253,10 @@ }, "The server refused a change. The changes before it were saved." : { + }, + "The server refused the connection. Check the host and port, and that the Oracle listener is running." : { + "extractionState" : "manual", + "generatesSymbol" : false }, "The server refused the request. Try again in a moment." : { diff --git a/apple/TablePro/Resources/ThirdPartyLicenses/licenses.yml b/apple/TablePro/Resources/ThirdPartyLicenses/licenses.yml index 5d90086e58..8b1ea61fe1 100644 --- a/apple/TablePro/Resources/ThirdPartyLicenses/licenses.yml +++ b/apple/TablePro/Resources/ThirdPartyLicenses/licenses.yml @@ -584,12 +584,12 @@ brew has installed (UNVERIFIED at build time; the shipped dylibs are the pinned 3.5.9). - id: oracle-nio name: OracleNIO - version: rev:045a44674e9f9da3904e0f2b87995490a7cc88e4 + version: rev:28d9d83b9b88440598862f04e43ca527dcac1d7d spdx: Apache-2.0 copyrights: - Copyright (c) 2023 Timo Zacherl homepageURL: https://github.com/TableProApp/oracle-nio - licenseTextURL: https://github.com/TableProApp/oracle-nio/blob/045a44674e9f9da3904e0f2b87995490a7cc88e4/LICENSE + licenseTextURL: https://github.com/TableProApp/oracle-nio/blob/28d9d83b9b88440598862f04e43ca527dcac1d7d/LICENSE textFile: texts/oracle-nio.txt source: spm:oracle-nio patched: false diff --git a/apple/TableProMobile/TableProMobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/apple/TableProMobile/TableProMobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 00bb980a7b..7a3e38290e 100644 --- a/apple/TableProMobile/TableProMobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/apple/TableProMobile/TableProMobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -15,7 +15,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/TableProApp/oracle-nio", "state" : { - "revision" : "045a44674e9f9da3904e0f2b87995490a7cc88e4" + "revision" : "28d9d83b9b88440598862f04e43ca527dcac1d7d" } }, { diff --git a/apple/TableProMobile/TableProMobile/Acknowledgements/Acknowledgements.json b/apple/TableProMobile/TableProMobile/Acknowledgements/Acknowledgements.json index 348162c1b2..8c86cf11d2 100644 --- a/apple/TableProMobile/TableProMobile/Acknowledgements/Acknowledgements.json +++ b/apple/TableProMobile/TableProMobile/Acknowledgements/Acknowledgements.json @@ -116,7 +116,7 @@ { "id": "oracle-nio", "name": "OracleNIO", - "version": "rev:045a44674e9f9da3904e0f2b87995490a7cc88e4", + "version": "rev:28d9d83b9b88440598862f04e43ca527dcac1d7d", "spdx": "Apache-2.0", "copyrights": [ "Copyright (c) 2023 Timo Zacherl" diff --git a/apple/TableProMobile/TableProMobile/Localizable.xcstrings b/apple/TableProMobile/TableProMobile/Localizable.xcstrings index 8b7844128f..a7e5cb3738 100644 --- a/apple/TableProMobile/TableProMobile/Localizable.xcstrings +++ b/apple/TableProMobile/TableProMobile/Localizable.xcstrings @@ -15568,6 +15568,10 @@ } } }, + "no answer within %lld seconds" : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "No columns found in the file." : { }, @@ -26036,6 +26040,10 @@ } } }, + "the host name could not be resolved" : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "The IAM Identity Center sign-in on this device has expired." : { }, @@ -26477,6 +26485,30 @@ "extractionState" : "manual", "generatesSymbol" : false }, + "The Oracle listener redirected the connection to %@, which could not be reached." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %@, which expects TLS. Set an SSL mode for this connection." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %@, which the tunnel does not forward. Enter that host and port as this connection's host and port so the tunnel reaches them." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %1$@, and the listener there refused it. %2$@" : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to %1$@, which could not be reached (%2$@)." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listener redirected the connection to an address TablePro could not read." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "The Oracle listener refused the connection (ORA-%ld)." : { "extractionState" : "manual", "generatesSymbol" : false, @@ -26537,6 +26569,14 @@ } } }, + "The Oracle listeners redirected the connection too many times." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, + "The Oracle listeners redirected the connection too many times. The last address was %@." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "The Oracle server accepted the connection but stopped answering during the login." : { "extractionState" : "manual", "generatesSymbol" : false @@ -27207,6 +27247,10 @@ "extractionState" : "manual", "generatesSymbol" : false }, + "The server refused the connection. Check the host and port, and that the Oracle listener is running." : { + "extractionState" : "manual", + "generatesSymbol" : false + }, "The server refused the request. Try again in a moment." : { }, diff --git a/apple/changelog.d/4610.fixed.md b/apple/changelog.d/4610.fixed.md new file mode 100644 index 0000000000..04b2229667 --- /dev/null +++ b/apple/changelog.d/4610.fixed.md @@ -0,0 +1 @@ +Oracle connections failed with OracleRedirectError when a RAC SCAN listener or shared server redirected them. diff --git a/apple/scripts/probes/check-oracle-listener-redirect.sh b/apple/scripts/probes/check-oracle-listener-redirect.sh new file mode 100755 index 0000000000..8402ca6540 --- /dev/null +++ b/apple/scripts/probes/check-oracle-listener-redirect.sh @@ -0,0 +1,164 @@ +#!/usr/bin/env bash +# +# Check that a connect follows an Oracle listener's TNS redirect, and that one it may not follow names the target. +# +# A RAC SCAN listener, a shared server dispatcher or Connection Manager answers a CONNECT with a REDIRECT. From 19c the +# REDIRECT holds only the data length and the address comes in the DATA packet after it (measured on 23.26). This turns +# an Oracle Free container into a SCAN-style rig: a second listener on serves the instance, and the +# default listener on 1521 only knows it as a remote listener, so every connect to 1521 is redirected to +# 127.0.0.1:. It then connects through the same OracleCoreConnection the app uses and checks that the +# redirect is followed, that a tunneled connect refuses it and names the target, and that a refused port fails at once. +# +# Usage: +# scripts/probes/check-oracle-listener-redirect.sh [container] [listener port] [redirect port] +# +# The container publishes 1521 on and the redirect port on the same port number, since the Mac dials +# the address the listener names: +# docker run -d --name oracle-redirect-probe -p 15211:1521 -p 15212:15212 -e ORACLE_PASSWORD=probe_pw \ +# -e APP_USER=probe -e APP_USER_PASSWORD=probe_pw gvenzl/oracle-free:23-slim-faststart +# +# The listener settings are made in memory and do not survive a restart. Exits non-zero on a disagreement, 3 when a +# prerequisite is missing. + +set -uo pipefail + +CONTAINER="${1:-oracle-redirect-probe}" +LISTENER_PORT="${2:-15211}" +REDIRECT_PORT="${3:-15212}" +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" + +command -v docker > /dev/null || { + echo "docker not found" >&2 + exit 3 +} +docker exec "$CONTAINER" true 2> /dev/null || { + echo "container $CONTAINER is not running" >&2 + exit 3 +} + +if [ -z "${DEVELOPER_DIR:-}" ]; then + for candidate in /Applications/Xcode-beta.app /Applications/Xcode.app; do + if [ -d "$candidate/Contents/Developer" ]; then + export DEVELOPER_DIR="$candidate/Contents/Developer" + break + fi + done +fi +command -v swift > /dev/null || { + echo "swift not found" >&2 + exit 3 +} + +echo "Setting up LISTENER2 on $REDIRECT_PORT inside $CONTAINER" +docker exec -i "$CONTAINER" bash -s "$REDIRECT_PORT" <<'EOF' || exit 3 +set -e +port="$1" +listener_ora="$ORACLE_HOME/network/admin/listener.ora" +if ! grep -q '^LISTENER2' "$listener_ora" 2> /dev/null; then + printf '\nLISTENER2 = (DESCRIPTION_LIST=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=0.0.0.0)(PORT=%s))))\n' "$port" >> "$listener_ora" +fi +lsnrctl status LISTENER2 > /dev/null 2>&1 || lsnrctl start LISTENER2 > /dev/null +sqlplus -s / as sysdba > /dev/null < "$WORK/Package.swift" < "$WORK/Sources/Probe/main.swift" <<'EOF' +import Foundation +import TableProOracleCore + +let arguments = CommandLine.arguments +let listenerPort = Int(arguments[1]) ?? 15_211 +let redirectPort = Int(arguments[2]) ?? 15_212 + +var disagreements = 0 + +@MainActor +func check(_ holds: Bool, _ claim: String) { + print("\(holds ? "ok " : "FAIL") \(claim)") + if !holds { disagreements += 1 } +} + +func options(port: Int, follows: Bool = true) -> OracleConnectionOptions { + OracleConnectionOptions( + host: "127.0.0.1", port: port, user: "probe", password: "probe_pw", + identifierMode: .service, serviceName: "FREEPDB1", loginTimeoutSeconds: 15, + followsListenerRedirects: follows + ) +} + +let tunneled = OracleCoreConnection(options: options(port: listenerPort, follows: false)) +do { + try await tunneled.connect() + check(false, "the listener on \(listenerPort) redirects (it accepted the connect instead)") + tunneled.disconnect() +} catch let error as OracleCoreError { + check( + error == .listenerRedirectFailed(.throughTunnel, target: "127.0.0.1:\(redirectPort)"), + "a connect that may not follow the redirect names its target: \(error.errorDescription ?? "")" + ) +} catch { + check(false, "a connect that may not follow the redirect names its target: \(error)") +} + +let followed = OracleCoreConnection(options: options(port: listenerPort)) +do { + try await followed.connect() + let answer = try? await followed.executeQuery("SELECT 'redirected' FROM DUAL") + check(answer?.rows.first?.first?.stringValue == "redirected", "the redirect is followed and the session answers") + followed.disconnect() +} catch { + check(false, "the redirect is followed: \((error as? OracleCoreError)?.errorDescription ?? "\(error)")") +} + +let refused = OracleCoreConnection(options: options(port: 1)) +let started = ContinuousClock.now +do { + try await refused.connect() + check(false, "a refused port fails") +} catch { + let elapsed = ContinuousClock.now - started + check( + (error as? OracleCoreError) == .connectionRefused && elapsed < .seconds(3), + "a refused port says so at once (\(elapsed.formatted(.units(allowed: [.seconds, .milliseconds])))): \(error)" + ) +} + +print(disagreements == 0 ? "\nall checks hold" : "\n\(disagreements) disagreement(s)") +exit(disagreements == 0 ? 0 : 1) +EOF + +echo "Building the probe against Packages/TableProOracle (the first build takes a minute)" +(cd "$WORK" && swift build -c debug > "$WORK/build.log" 2>&1) || { + grep -E "error:" "$WORK/build.log" | head -20 >&2 + exit 3 +} +"$WORK/.build/debug/Probe" "$LISTENER_PORT" "$REDIRECT_PORT" 2> /dev/null