sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.42k stars 436 forks source link

Tokio Postgres hangs #1063

Closed FaveroFerreira closed 12 months ago

FaveroFerreira commented 1 year ago

Bug Description

Tokio Postgres hangs when running CREATE DATABASE query. awaiting it never returns.

In this example I am using simple_query, but it also happens with execute and query methods.

All other queries works fine.

Minimal Reproduction

async fn seed_database(db_config: &PostgresConfig) {
    let without_db = format!(
        "postgres://{}:{}@{}:{}/postgres",
        db_config.username.expose_secret(),
        db_config.password.expose_secret(),
        db_config.host,
        5432
    );

    let (client, _conn) = tokio_postgres::connect(&without_db, tokio_postgres::NoTls)
        .await
        .expect("Failed to connect to Postgres");

    client
        .simple_query(&format!("CREATE DATABASE \"{}\"", db_config.database))
        .await
        .expect("Failed to create database");

  // ....
}

Info

sfackler commented 1 year ago

Don't ignore conn.

FaveroFerreira commented 1 year ago

Tried it, sadly it behaves the same.

sfackler commented 1 year ago

What is "it"? What are you doing with conn?

FaveroFerreira commented 12 months ago

Sorry for the late response, I realised I was not spawning the conn to a separate thread. My bad.