rust-async-review
Skill0 starsChanged 3 days agoMITView on GitHub
Review async Rust built on tokio - blocking calls on runtime threads (std thread sleep, std fs and net, reqwest blocking), std Mutex guards held across await (non-Send futures, deadlocks), block_on inside async code, futures never awaited, unbounded channels without backpressure, detached tokio spawn without JoinSet, cancellation safety in select, timeouts, graceful shutdown and runtime choice in libraries. Includes a scanner that pre-flags these patterns with file and line. Use when the user asks to review tokio code, sees "future cannot be sent between threads safely", "Cannot start a runtime from within a runtime", a stalled or slow async service, or wants to add timeouts, shutdown handling or bounded concurrency.
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rust-borrow-checkerSkill
- rust-crates-publishSkill
- rust-dependency-auditSkill
- rust-error-handlingSkill
- rust-lint-ciSkill
- rust-testing-benchesSkill
- rust-unsafe-reviewSkill
- rust-workspace-setupSkill
The file
Files
Async and tokio review
Goal: no blocking work on runtime worker threads, no lock guards across .await, every
spawned task is owned (joined or cancelled), and every external call has a timeout.
Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).
When to use
- "Review my tokio code", "the service stalls under load", "latency spikes"
- Errors:
future cannot be sent between threads safely,Cannot start a runtime from within a runtime,cannot drop a runtime in a context where blocking is not allowed - Designing shutdown, timeouts, retries or concurrency limits
- Choosing
tokio::sync::Mutexvsstd::sync::Mutex
When not to use
- Plain borrow errors in async fns that are not about
Send:rust-borrow-checker - Unsafe code in async executors or FFI:
rust-unsafe-review - Benchmarking async code:
rust-testing-benches(criterion has async support)
Workflow
- Scan (read-only, heuristic):
A trailingpython3 scripts/async_audit.py . python3 scripts/async_audit.py src/ --json --fail-on high// async-audit: allowcomment silences a reviewed line. Confirm each finding by reading the code; the scanner does not resolve types. - Fix blocking calls: async equivalents (
tokio::time::sleep,tokio::fs,tokio::net, asyncreqwest::Client) or move CPU-heavy / blocking work intotokio::task::spawn_blocking. Patterns in references/patterns.md. - Fix guards across await: scope the
std::sync::Mutexguard in a block that ends before the.await, or copy the data out. Usetokio::sync::Mutexonly if the lock truly must be held across an await (it is slower). - Own your tasks:
JoinSetfor fan-out,Semaphoreorbuffer_unordered(n)for bounded concurrency,CancellationToken(tokio-util) or awatchchannel for shutdown. See references/patterns.md. - Check
select!branches for cancellation safety (a branch that loses data when another branch wins), using the table in references/patterns.md. - Timeouts and backpressure: wrap network calls in
tokio::time::timeout, replaceunbounded_channelwithchannel(capacity)unless producers are bounded. - Verify:
cargo check --all-targets,cargo test, and for runtime behaviourtokio-console(needsconsole-subscriberand--cfg tokio_unstable) or thetokio::runtime::Handle::metrics()API. If you cannot run them, list the commands.
Decision points
| Situation | Choice |
| Short critical section, no await inside | std::sync::Mutex (or parking_lot) |
| Must await while holding the lock | tokio::sync::Mutex, or redesign as an actor (task + mpsc) |
| Read-mostly config | ArcSwap or tokio::sync::watch |
| CPU-bound work (hashing, compression, parsing big files) | spawn_blocking or rayon |
| Library crate | expose async fns, no #[tokio::main], enable only needed tokio features |
| Tests | #[tokio::test], start_paused = true for time-based logic |
Output
async_audit: 7 findings (3 high) in src/main.rs
HIGH src/main.rs:10 std Mutex guard `hits` alive across .await -> scoped block (diff)
HIGH src/main.rs:13 std::thread::sleep in async fn -> tokio::time::sleep(..).await
MED src/main.rs:15 tokio::time::sleep(..) not awaited -> added .await
Design: tasks now in a JoinSet, shutdown via CancellationToken, HTTP calls have 10 s timeoutsDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

