Skip to content
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

AsyncPgConnection SSL error when PgConnection works #73

Closed
3 tasks done
roudikk opened this issue Apr 16, 2023 · 1 comment
Closed
3 tasks done

AsyncPgConnection SSL error when PgConnection works #73

roudikk opened this issue Apr 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@roudikk
Copy link

roudikk commented Apr 16, 2023

When trying to connect to my database using AsyncPgConnection I get a SSL error but it works using PgConnection

Setup

My postgres URL is just a simple username/password postgres:// url with no additional query params.

Cargo.toml

[dependencies]
diesel = { version = "2.0.3", features = ["postgres", "r2d2", "extras", "chrono", "uuid"] }
diesel-async = { version = "0.2.1", features = ["postgres", "bb8"] }
dotenv = "0.15.0"
serde = { version = "1.0.159", features = ["derive"]}
serde_json = "1.0.95"
chrono = { version = "0.4.24", features = ["serde"] }
bb8 = "0.8"
axum = "0.6.12"
axum-macros = "0.3.7"
tokio = { version = "1.27.0", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }

Steps to reproduce

Using PgConnection:

#[tokio::main]
async fn main() {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");

    let mut connection = PgConnection::establish(&database_url).unwrap();
    println!("Established!");
    let orgs = orgs::table.load::<Org>(&mut connection).unwrap();
    println!("{:?}", orgs);
}

Output:

Established!
[]

Using AsyncPgConnection:

#[tokio::main]
async fn main() {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");

    let mut connection = AsyncPgConnection::establish(&database_url).await.unwrap();
    println!("Established!");
    let orgs = orgs::table.load::<Org>(&mut connection).await.unwrap();
    println!("{:?}", orgs);

Output

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CouldntSetupConfiguration(DatabaseError(Unknown, "SSL/TLS required"))', src\main.rs:27:76

Checklist

  • I have already looked over the issue tracker for similar possible closed issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate
@roudikk roudikk added the bug Something isn't working label Apr 16, 2023
@roudikk roudikk changed the title AsyncPgConnection AsyncPgConnection SSL error when PgConnection works Apr 16, 2023
@weiznich
Copy link
Owner

This is expected behavior as tokio-postgres does not provide support for TLS/SSL connections by default. You need to setup that by including additional dependencies. As there are multiple options there I choose to not include that directly in diesel. You can construct a AsyncPgConnection for a tokio-postgres Client that supports TLS/SSL connections via AsyncPgConnection::try_from.

Also see this example: https://github.com/weiznich/diesel_async/tree/main/examples/postgres/pooled-with-rustls

Closed as this is not an bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants