ITADN

`PostgresClient.query()` does not throw upon `PostgresClient.options.connectTimeout`!

#574Openah-row 创建于 2025-07-26
bug
A
ah-rowcommented
### Describe the issue `PostgresClient.query()` nor `PostgresConnection.query()` do not throw upon `PostgresClient.options.connectTimeout`! ### Vapor version postgres-nio 1.26.2 ### Operating system and version macOS 15.5 ### Swift version Apple Swift version 6.1 (swift-6.1-RELEASE) ### Steps to reproduce # Expected postgres-nio should throw an error once `PostgresClient.options.connectTimeout` has elapsed. # Observed While postgres-nio does log an error, it does not *throw* an error. This prevents any caller from dealing with any potential problem of an unreachable server. # How was this conclusion reached? By using code similar to what can be found in `Tests/IntegrationTests/PostgresClientTests.swift`, we can create a `PostgresClient.Configuration` pointing to a non-responding server with the goal to ensure the library fails predictably! It does not! ```swift @Test("Postgres Connection Timeout! This should throw!") func connectionTimeout() async throws { let nonRespondingServer = PostgresClient.Configuration(…) let client = PostgresClient(configuration: nonRespondingServer, backgroundLogger: logger) try await withThrowingTaskGroup(of: Void.self) { taskGroup in defer { taskGroup.cancelAll() } taskGroup.addTask { await client.run() // Only returns once the taskGroup is canceled; } // Give `client.run()` a few seconds for the client to setup. (In case of Fragile API?!) try await Task.sleep(for: .seconds(5)) taskGroup.addTask { //⚠️ Following call does not throw after timeout! //try await client.query("SELECT 1", logger: logger) try await client.withConnection() { connection in _ = try await connection.query("SELECT 1", logger: logger) } } do { try await taskGroup.next() // Wait until *any* task in group returns/throws logger.debug("A task completed!") // ⚠️ This is NEVER reached because the query can't run (server doesn't respond) // nor does it give-up (and throw) after `PostgresClient.options.connectTimeout` has elapsed. } catch let e { print("client.next() threw an error!") // ⚠️ This is NEVER reached because an error is not thrown after // after `PostgresClient.options.connectTimeout` has elapsed. taskGroup.cancelAll() throw e } } } ``` ### Outcome No error is thrown, ### Additional notes _No response_
1 条评论