Skip to content

Commit cb4c975

Browse files
committed
WIP pool changes
1 parent 4efc16b commit cb4c975

File tree

16 files changed

+879
-538
lines changed

16 files changed

+879
-538
lines changed

Cargo.lock

+21-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ authors = [
3535
"Chloe Ross <[email protected]>",
3636
"Daniel Akhterov <[email protected]>",
3737
]
38-
# TODO: enable this for 0.9.0
39-
# rust-version = "1.80.0"
38+
rust-version = "1.80.0"
4039

4140
[package]
4241
name = "sqlx"
@@ -48,6 +47,7 @@ license.workspace = true
4847
edition.workspace = true
4948
authors.workspace = true
5049
repository.workspace = true
50+
rust-version.workspace = true
5151

5252
[package.metadata.docs.rs]
5353
features = ["all-databases", "_unstable-all-types"]
@@ -147,6 +147,7 @@ uuid = "1.1.2"
147147

148148
# Common utility crates
149149
dotenvy = { version = "0.15.0", default-features = false }
150+
ease-off = "0.1.4"
150151

151152
# Runtimes
152153
[workspace.dependencies.async-std]

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Note: should NOT increase during a minor/patch release cycle
22
[toolchain]
3-
channel = "1.78"
3+
channel = "1.80"
44
profile = "minimal"

sqlx-core/Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ any = []
1919
json = ["serde", "serde_json"]
2020

2121
# for conditional compilation
22-
_rt-async-std = ["async-std", "async-io"]
23-
_rt-tokio = ["tokio", "tokio-stream"]
22+
_rt-async-std = ["async-std", "async-io", "ease-off/async-io-2"]
23+
_rt-tokio = ["tokio", "tokio-stream", "ease-off/tokio"]
2424
_tls-native-tls = ["native-tls"]
2525
_tls-rustls-aws-lc-rs = ["_tls-rustls", "rustls/aws-lc-rs"]
2626
_tls-rustls-ring = ["_tls-rustls", "rustls/ring"]
@@ -59,7 +59,6 @@ crossbeam-queue = "0.3.2"
5959
either = "1.6.1"
6060
futures-core = { version = "0.3.19", default-features = false }
6161
futures-io = "0.3.24"
62-
futures-intrusive = "0.5.0"
6362
futures-util = { version = "0.3.19", default-features = false, features = ["alloc", "sink", "io"] }
6463
log = { version = "0.4.18", default-features = false }
6564
memchr = { version = "2.4.1", default-features = false }
@@ -81,6 +80,9 @@ indexmap = "2.0"
8180
event-listener = "5.2.0"
8281
hashbrown = "0.14.5"
8382

83+
ease-off = { workspace = true, features = ["futures"] }
84+
pin-project-lite = "0.2.14"
85+
8486
[dev-dependencies]
8587
sqlx = { workspace = true, features = ["postgres", "sqlite", "mysql", "migrate", "macros", "time", "uuid"] }
8688
tokio = { version = "1", features = ["rt"] }

sqlx-core/src/error.rs

+34-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use crate::database::Database;
1111
use crate::type_info::TypeInfo;
1212
use crate::types::Type;
1313

14+
#[cfg(doc)]
15+
use crate::pool::{PoolConnector, PoolOptions};
16+
1417
/// A specialized `Result` type for SQLx.
1518
pub type Result<T, E = Error> = ::std::result::Result<T, E>;
1619

@@ -104,6 +107,19 @@ pub enum Error {
104107
#[error("attempted to acquire a connection on a closed pool")]
105108
PoolClosed,
106109

110+
/// A custom error that may be returned from a [`PoolConnector`] implementation.
111+
#[error("error returned from pool connector")]
112+
PoolConnector {
113+
#[source]
114+
source: BoxDynError,
115+
116+
/// If `true`, `PoolConnector::connect()` is called again in an exponential backoff loop
117+
/// up to [`PoolOptions::connect_timeout`].
118+
///
119+
/// See [`PoolConnector::connect()`] for details.
120+
retryable: bool,
121+
},
122+
107123
/// A background worker has crashed.
108124
#[error("attempted to communicate with a crashed background worker")]
109125
WorkerCrashed,
@@ -202,11 +218,6 @@ pub trait DatabaseError: 'static + Send + Sync + StdError {
202218
#[doc(hidden)]
203219
fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static>;
204220

205-
#[doc(hidden)]
206-
fn is_transient_in_connect_phase(&self) -> bool {
207-
false
208-
}
209-
210221
/// Returns the name of the constraint that triggered the error, if applicable.
211222
/// If the error was caused by a conflict of a unique index, this will be the index name.
212223
///
@@ -244,6 +255,24 @@ pub trait DatabaseError: 'static + Send + Sync + StdError {
244255
fn is_check_violation(&self) -> bool {
245256
matches!(self.kind(), ErrorKind::CheckViolation)
246257
}
258+
259+
/// Returns `true` if this error can be retried when connecting to the database.
260+
///
261+
/// Defaults to `false`.
262+
///
263+
/// For example, the Postgres driver overrides this to return `true` for the following error codes:
264+
///
265+
/// * `53300 too_many_connections`: returned when the maximum connections are exceeded
266+
/// on the server. Assumed to be the result of a temporary overcommit
267+
/// (e.g. an extra application replica being spun up to replace one that is going down).
268+
/// * This error being consistently logged or returned is a likely indicator of a misconfiguration;
269+
/// the sum of [`PoolOptions::max_connections`] for all replicas should not exceed
270+
/// the maximum connections allowed by the server.
271+
/// * `57P03 cannot_connect_now`: returned when the database server is still starting up
272+
/// and the tcop component is not ready to accept connections yet.
273+
fn is_retryable_connect_error(&self) -> bool {
274+
false
275+
}
247276
}
248277

249278
impl dyn DatabaseError {

0 commit comments

Comments
 (0)