sfackler / rust-postgres

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

Add hostaddr support #945

Closed trungda closed 1 year ago

trungda commented 2 years ago

More details in https://github.com/sfackler/rust-postgres/issues/943. Essentially, if we could provide both host and hostaddr, we can avoid an extra DNS lookup to establish a connection to the DB. Specifically, if both host and hostaddr are provided, hostaddr is going to be used to create the socket, i.e., as a raw IP address. host is still needed for TLS validation.

Testing

cargo test returns 4 failing tests which are already failing in master

---- test::scram_user stdout ----
thread 'test::scram_user' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Tls, cause: Some(Error { code: -67843, message: "The certificate was not trusted." }) }', postgres-native-tls/src/test.rs:18:71
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- test::require stdout ----
thread 'test::require' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Tls, cause: Some(Error { code: -67843, message: "The certificate was not trusted." }) }', postgres-native-tls/src/test.rs:18:71

---- test::runtime stdout ----
thread 'test::runtime' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Tls, cause: Some(Error { code: -67843, message: "The certificate was not trusted." }) }', postgres-native-tls/src/test.rs:91:6

---- test::prefer stdout ----
thread 'test::prefer' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Tls, cause: Some(Error { code: -67843, message: "The certificate was not trusted." }) }', postgres-native-tls/src/test.rs:18:71

failures:
    test::prefer
    test::require
    test::runtime
    test::scram_user

test result: FAILED. 0 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s

I would be happy to make them work again in future PRs.

trungda commented 2 years ago

@sfackler could you help take a look at the latest commit? Thank you :)

trungda commented 2 years ago

@sfackler could you help take a look? Thank you :)

trungda commented 2 years ago

@sfackler could you help take a look? Thanks :)

trungda commented 2 years ago

@sfackler would be great if you could take a look :) We have to use a forked version of rust-postgres now and I am worried it might be diverged from upstream :)

trungda commented 1 year ago

@sfackler could you help take a look? Thank you :) !

trungda commented 1 year ago

@sfackler happy holidays :) Could you help take a look at this PR? I am happy to address any feedback you might have. Thank you!

trungda commented 1 year ago

@sfackler could you help take a look at this PR :) Thank you!

trungda commented 1 year ago

@sfackler could you help take a look :) We have been running this branch in production for a few months now so I am confident that this works.

trungda commented 1 year ago

Hi @sfackler , could you help review this PR when you have time? Thank you :)

trungda commented 1 year ago

Hi @sfackler , could you help take a look at this PR when you have time :) Thank you!

sfackler commented 1 year ago

Sorry for the very long delay! This looks good to me.

trungda commented 1 year ago

Sorry for the very long delay! This looks good to me.

Thank you @sfackler ! Happy to contribute more to the project!