Skip to content

rust.sqlx.query_without_timeout

Stability High

Detects SQLx queries without timeout configuration that can hang indefinitely.

Queries without timeout:

  • Connection pool exhaustion — Slow queries hold connections
  • Request timeouts — Users wait forever
  • Cascading failures — DB issues spread to app
// ❌ Before (no query timeout)
async fn get_report(pool: &PgPool) -> Report {
sqlx::query_as!(Report, "SELECT * FROM large_table")
.fetch_one(pool)
.await?
}
// ✅ After (with timeout)
use tokio::time::{timeout, Duration};
async fn get_report(pool: &PgPool) -> Result<Report, Error> {
timeout(Duration::from_secs(30), async {
sqlx::query_as!(Report, "SELECT * FROM large_table")
.fetch_one(pool)
.await
}).await.map_err(|_| Error::Timeout)??
}

Or configure at pool level:

// Pool-level timeout
let pool = PgPoolOptions::new()
.acquire_timeout(Duration::from_secs(5))
.connect(&database_url)
.await?;
  • Queries without tokio timeout wrapper
  • Missing pool acquire_timeout
  • Long-running queries without limits

Unfault can wrap queries with timeout.