transact-rs/sqlx · critical

one of the `runtime` features of SQLx must be enabled

Error message

one of the `runtime` features of SQLx must be enabled

What it means

The second branch of missing_rt() in sqlx-core/src/rt/mod.rs: panics when NO sqlx `runtime` feature is enabled at compile time (`cfg!(feature = "_rt-tokio")` is false). sqlx's runtime-independent API needs at least one `runtime-*` feature to select the async executor implementation; without it, any API that touches the runtime abstraction cannot work.

Source

Thrown at sqlx-core/src/rt/mod.rs:169

        } else if #[cfg(feature = "_rt-tokio")] {
            tokio::runtime::Builder::new_current_thread()
                .enable_all()
                .build()
                .expect("failed to start Tokio runtime")
                .block_on(f)
        } else {
            missing_rt(f)
        }
    }
}

#[track_caller]
pub const fn missing_rt<T>(_unused: T) -> ! {
    if cfg!(feature = "_rt-tokio") {
        panic!("this functionality requires a Tokio context")
    }

    panic!("one of the `runtime` features of SQLx must be enabled")
}

impl<T: Send + 'static> Future for JoinHandle<T> {
    type Output = T;

    #[track_caller]
    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        match &mut *self {
            #[cfg(feature = "_rt-async-std")]
            Self::AsyncStd(handle) => Pin::new(handle).poll(cx),

            #[cfg(feature = "_rt-async-task")]
            Self::AsyncTask(task) => Pin::new(task)
                .as_pin_mut()
                .expect("BUG: task taken")
                .poll(cx),

            #[cfg(feature = "_rt-tokio")]

View on GitHub (pinned to 03af8bcc57)

Solutions

  1. Add a runtime feature: `sqlx = { features = ["runtime-tokio", "postgres"] }` (or `-rustls`/`-native-tls` variants).
  2. Search the workspace for `default-features = false` on the sqlx dependency and ensure at least one member enables a runtime feature.
  3. Run `cargo tree -i sqlx` and `cargo tree -e features` to confirm which feature set is actually compiled in.

Example fix

// before (Cargo.toml)
sqlx = { version = "0.8", features = ["postgres"], default-features = false }

// after
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres"], default-features = false }
Defensive patterns

Strategy: validation

Validate before calling

// Cargo.toml — fail compilation if no runtime feature:
[features]
default = ["runtime-tokio"]

// or in code:
#[cfg(not(any(feature = "runtime-tokio")))]
compile_error!("sqlx requires a runtime-* feature");

Prevention

When it happens

Trigger: Using sqlx with Cargo.toml features that omit any `runtime-*` feature, e.g. `features = ["postgres"]` only, or `default-features = true` lost via a dependency that re-specifies sqlx without runtime features. Any pool/connect/query call then panics at first use.

Common situations: Feature unification surprises: a workspace member enables sqlx with `default-features = false` and no runtime feature; copying a minimal Cargo.toml snippet; upgrading to sqlx 0.7+ where `runtime-async-std` etc. were removed/renamed.

Related errors


AI-assisted analysis of transact-rs/sqlx@03af8bcc57 (2026-09-03). Data as JSON: /api/errors/7f8124a92e585507. Report an issue: GitHub.