Skip to content

rust.axum.missing_timeout

Stability Medium

Detects Axum handlers without request timeout middleware.

Without request timeouts:

  • Resource exhaustion — Slow requests hold connections
  • Cascading failures — Backed up requests overwhelm the service
  • No SLA enforcement — Can’t guarantee response times
  • Memory growth — Pending requests accumulate

Timeouts are essential for resilient services.

// ❌ Before
use axum::{routing::get, Router};
let app = Router::new()
.route("/api/data", get(get_data));
// ✅ After
use axum::{routing::get, Router};
use tower_http::timeout::TimeoutLayer;
use std::time::Duration;
let app = Router::new()
.route("/api/data", get(get_data))
.layer(TimeoutLayer::new(Duration::from_secs(30)));
  • Axum Router without TimeoutLayer
  • Missing timeout on specific routes

Unfault adds a 30-second timeout layer.

use axum::{routing::get, Router};
use tower_http::timeout::TimeoutLayer;
// Different timeouts for different routes
let fast_routes = Router::new()
.route("/health", get(health))
.layer(TimeoutLayer::new(Duration::from_secs(5)));
let slow_routes = Router::new()
.route("/report", get(generate_report))
.layer(TimeoutLayer::new(Duration::from_secs(60)));
let app = Router::new()
.merge(fast_routes)
.merge(slow_routes);