Skip to content

Trying to connecting to non-existing database using PostgresClient, queries hang indefinitely with no error thrown #602

@ahoppen

Description

@ahoppen

When using PostgresClient and trying to connect to a database that doesn’t exist, no error is thrown. Instead, any attempt to run a query just hangs, no error is thrown. When connecting using PostgresConnection, an error is thrown at connection time.

To reproduce, add the following test to IntegrationTests/PostgresNIOTests.swift and run it. Notice how it just hangs, I would have expected an error to be thrown from query.

func testConnectToNonexistingDatabase() async throws {
    let config = PostgresClient.Configuration(
        host: env("POSTGRES_HOSTNAME") ?? "localhost",
        port: env("POSTGRES_PORT").flatMap(Int.init(_:)) ?? 5432,
        username: env("POSTGRES_USER") ?? "test_username",
        password: env("POSTGRES_PASSWORD") ?? "test_password",
        database: "does_not_exist",
        tls: .disable
    )
    let client = PostgresClient(configuration: config)
    try await withThrowingTaskGroup { taskGroup in
        taskGroup.addTask {
            await client.run()
        }
        try await client.query("SELECT 1")
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions