rust-doctor
Rules

Async Rules

Rules for detecting async anti-patterns in Rust code.

blocking-in-async

Severity: Warning

Detects blocking I/O calls (std::fs::read, std::thread::sleep, etc.) inside async functions. These block the tokio runtime thread and degrade performance.

// Bad
async fn load_config() -> Config {
    let data = std::fs::read_to_string("config.toml").unwrap();
    parse(data)
}

// Good
async fn load_config() -> Config {
    let data = tokio::fs::read_to_string("config.toml").await.unwrap();
    parse(data)
}

block-on-in-async

Severity: Error

Detects block_on() calls inside async contexts. This causes deadlocks when the runtime's thread pool is exhausted.

// Bad
async fn fetch_data() -> Data {
    tokio::runtime::Handle::current().block_on(async {
        // deadlock risk
    })
}

// Good
async fn fetch_data() -> Data {
    some_async_operation().await
}

On this page