Skip to content

100% CPU in sqlx_core::pool::inner::spawn_maintenance_tasks #3645

Open
@ivan

Description

@ivan

Bug Description

About one in ten thousand processes, I am seeing sqlx 0.8.2 consume 100% of a core; perf top -p PID says it's in

sqlx_core::pool::inner::spawn_maintenance_tasks::_$u7b$$u7b$closure$u7d$$u7d$::h88ca82fcaec74b9d

My sqlx pools are set to use 4 connections and I connect to a PostgreSQL 16.5 with thousands of clients.

I believe the 100% CPU use happens around process exit, because I don't see errors, and all the rows I INSERT do arrive in the database.

I use

sqlx = { version = "0.8.2", default-features = false, features = ["runtime-tokio-rustls", "macros", "postgres", "rust_decimal", "uuid", "chrono", "json"] }

and set up my pool with

pub async fn new_pgpool(uri: &str) -> Result<PgPool> {
    let options: PgConnectOptions = uri.parse::<PgConnectOptions>()?
        .log_slow_statements(LevelFilter::Info, Duration::from_secs(5));
    let pool = PgPoolOptions::new()
        .acquire_timeout(Duration::from_secs(30))
        .idle_timeout(Duration::from_secs(1)) // Reduce open sessions on the server
        .max_connections(4)
        .connect_with(options).await?;
    Ok(pool)
}

I am leaving this here as a pointer to "I'm pretty sure something is wrong with spawn_maintenance_tasks", and I will try to investigate this further later if nothing seems obviously wrong with it.

Minimal Reproduction

Sorry, I'll try to provide this in 2025...

Info

  • SQLx version: 0.8.2
  • SQLx features enabled: "runtime-tokio-rustls", "macros", "postgres", "rust_decimal", "uuid", "chrono", "json"
  • Database server and version: PostgreSQL 16.5
  • Operating system: NixOS 24.05
  • rustc --version: rustc 1.84.0-nightly (ee612c45f 2024-11-19) but it has also occurred in versions from a while back

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions