sync upstream v0.19.7#1
Open
xxchan wants to merge 76 commits into
Open
Conversation
…cp-keepalive-options OpenBSD misses some TCP keepalive options
refactor(types): improve readability of `impl ToSql for &str`
Fix serialization of oidvector
Add to_sql for bytes Cow as well
Implement load balancing
…ismatch feat(derive): add `#[postgres(allow_mismatch)]`
This mimics the behaviour of libpq and some other libraries (see rust-postgres#1024). This commit uses the `whoami` crate, and thus goes as far as defaulting the user to the executing process' user name on all operating systems.
`tokio-postgres`: Set user to executing process' user by default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The merge conflict resolution diff:
❯ git show f989f42 commit f989f421ad2d56a869e5bebca0219d179e3ecf0c (HEAD -> madsim, xxchan/madsim) Merge: 4538cd6b c5ff8cfd Author: xxchan <xxchan22f@gmail.com> Date: Sun Sep 10 00:08:13 2023 +0800 Merge branch 'master' into madsim diff --cc tokio-postgres/Cargo.toml index e6c7b4f7,ec5e3cbe..fefaddd0 --- a/tokio-postgres/Cargo.toml +++ b/tokio-postgres/Cargo.toml @@@ -53,17 -54,21 +54,21 @@@ parking_lot = "0.12 percent-encoding = "2.0" pin-project-lite = "0.2" phf = "0.11" - postgres-protocol = { version = "0.6.4" } - postgres-types = { version = "0.2.4" } - socket2 = { version = "0.5", features = ["all"] } -postgres-protocol = { version = "0.6.6", path = "../postgres-protocol" } -postgres-types = { version = "0.2.5", path = "../postgres-types" } -tokio = { version = "1.27", features = ["io-util"] } ++postgres-protocol = { version = "0.6.6" } ++postgres-types = { version = "0.2.5" } +tokio = { version = "0.2.2", package = "madsim-tokio", features = ["io-util"] } tokio-util = { version = "0.7", features = ["codec"] } + rand = "0.8.5" + whoami = "1.4.1" + + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] + socket2 = { version = "0.5", features = ["all"] } [dev-dependencies] futures-executor = "0.3" - criterion = "0.4" + criterion = "0.5" env_logger = "0.10" -tokio = { version = "1.0", features = [ +tokio = { version = "0.2", package = "madsim-tokio", features = [ "macros", "net", "rt", diff --cc tokio-postgres/src/connect_socket.rs index ae2359e7,f2713117..02dab3bd --- a/tokio-postgres/src/connect_socket.rs +++ b/tokio-postgres/src/connect_socket.rs @@@ -10,63 -11,40 +11,43 @@@ use tokio::net::UnixStream use tokio::time; pub(crate) async fn connect_socket( - host: &Host, + addr: &Addr, port: u16, connect_timeout: Option<Duration>, - tcp_user_timeout: Option<Duration>, + #[cfg_attr(not(target_os = "linux"), allow(unused_variables))] tcp_user_timeout: Option< + Duration, + >, keepalive_config: Option<&KeepaliveConfig>, ) -> Result<Socket, Error> { - match host { - Host::Tcp(host) => { - let addrs = net::lookup_host((&**host, port)) - .await - .map_err(Error::connect)?; + match addr { + Addr::Tcp(ip) => { + let stream = + connect_with_timeout(TcpStream::connect((*ip, port)), connect_timeout).await?; - let mut last_err = None; + stream.set_nodelay(true).map_err(Error::connect)?; - for addr in addrs { - let stream = - match connect_with_timeout(TcpStream::connect(addr), connect_timeout).await { - Ok(stream) => stream, - Err(e) => { - last_err = Some(e); - continue; - } - }; - - stream.set_nodelay(true).map_err(Error::connect)?; - - #[cfg(not(madsim))] - let sock_ref = SockRef::from(&stream); - #[cfg(target_os = "linux")] - #[cfg(not(madsim))] - { - sock_ref - .set_tcp_user_timeout(tcp_user_timeout) - .map_err(Error::connect)?; - } - - #[cfg(not(madsim))] - if let Some(keepalive_config) = keepalive_config { - sock_ref - .set_tcp_keepalive(&TcpKeepalive::from(keepalive_config)) - .map_err(Error::connect)?; - } ++ #[cfg(not(madsim))] + let sock_ref = SockRef::from(&stream); + #[cfg(target_os = "linux")] ++ #[cfg(not(madsim))] + { + sock_ref + .set_tcp_user_timeout(tcp_user_timeout) + .map_err(Error::connect)?; + } - return Ok(Socket::new_tcp(stream)); ++ #[cfg(not(madsim))] + if let Some(keepalive_config) = keepalive_config { + sock_ref + .set_tcp_keepalive(&TcpKeepalive::from(keepalive_config)) + .map_err(Error::connect)?; } - Err(last_err.unwrap_or_else(|| { - Error::connect(io::Error::new( - io::ErrorKind::InvalidInput, - "could not resolve any addresses", - )) - })) + Ok(Socket::new_tcp(stream)) } #[cfg(unix)] - Host::Unix(path) => { - let path = path.join(format!(".s.PGSQL.{}", port)); + Addr::Unix(dir) => { + let path = dir.join(format!(".s.PGSQL.{}", port)); let socket = connect_with_timeout(UnixStream::connect(path), connect_timeout).await?; Ok(Socket::new_unix(socket)) }or
git diff f989f42^2