Skip to content

Connecting to MySQL with SSL enabled blocks event loop #4026

@daviduebler

Description

@daviduebler

I have found these related issues/pull requests

maybe #4005

Description

Connecting to a MySQL server with SSL enabled blocks significantly longer than connecting without SSL.

Reproduction steps

use {
    tracing_subscriber::{
        fmt,
        filter::{ EnvFilter },
        prelude::*,
    },
    tracing::{ Instrument },
    sqlx::mysql::{ MySqlPoolOptions, MySqlSslMode, MySqlConnectOptions },
};

fn init_logging() {
    let format = fmt::layer()
        .with_span_events(fmt::format::FmtSpan::CLOSE)
        .with_target(true);

    let filter = EnvFilter::from_default_env();

    let registry = tracing_subscriber::registry()
        .with(filter)
        .with(format);

    registry.init();
}

const DB_URI: &str = "mysql://user:pass@host/db";

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    init_logging();

    let options = DB_URI.parse::<MySqlConnectOptions>()?;
    let options_no_ssl = options.clone().ssl_mode(MySqlSslMode::Disabled);

    MySqlPoolOptions::new()
        .connect_with(options)
        .instrument(tracing::info_span!("connect"))
        .await?;

    MySqlPoolOptions::new()
        .connect_with(options_no_ssl)
        .instrument(tracing::info_span!("connect_no_ssl"))
        .await?;

    Ok(())
}

Output on my machine:

2025-09-16T11:36:30.065098Z  INFO connect: sqlx_timing: close time.busy=41.5ms time.idle=4.56ms
2025-09-16T11:36:30.070216Z  INFO connect_no_ssl: sqlx_timing: close time.busy=691µs time.idle=3.7
2ms

Enabling SSL seems to block the event loop for tens of milliseconds.

SQLx version

0.8.6

Enabled SQLx features

mysql, runtime-tokio-native-tls, json, time

Database server and version

MySQL 8.0.31

Operating system

NixOS

Rust version

rustc 1.89.0-nightly (60dabef95 2025-05-19)

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