Skip to content

Common async pitfalls

Level: 201 · working knowledge

Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The bullets below are the questions the finished page has to answer.

One line: Most async bugs compile — a future nobody awaits, a worker thread stuck in a blocking call, a lock held across a suspension point — so each one needs a name and a symptom you can recognise.

What it has to cover

Each pitfall with its symptom, and the chapter where the fix is built:

Pitfall What you see Fixed in
A future created and never awaited nothing happens; one warning What a future is
A blocking call (std::thread::sleep, file IO, a long computation) inside a task every other task on that worker stalls Tasks, Diagnosing a stuck runtime
A std::sync::MutexGuard held across .await tokio::spawn refuses the future as not Send; unspawned, it can deadlock Who owns the state
Borrowing a local into a spawned task the 'static error Tasks
A task spawned and never joined its panic reaches stderr and nothing else — no error, no restart Shutdown and supervision
A future dropped mid-way inside select! data read but never processed Cancellation
An unbounded channel memory grows until the process dies Backpressure
block_on called from inside the runtime a panic, at run time Diagnosing a stuck runtime
A test that depends on scheduling order passes locally, flakes in CI Testing async code
  • For each row: the smallest program that shows it, and whether the compiler, Clippy, or nothing at all catches it
  • Why most of these are silent: the compiler checks types across .await, not timing

See also

Po polsku

Najgroźniejsze błędy asynchroniczne w Ruscie kompilują się bez ostrzeżeń: blokujące wywołanie w zadaniu zatrzymuje wszystkie inne zadania na tym samym wątku roboczym, blokada ze std::sync trzymana przez .await kończy się zakleszczeniem albo błędem Send, a panika w zadaniu, na które nikt nie czeka, znika bez śladu. Ta strona zbiera je w jednej tabeli i odsyła do rozdziału, który każdy z nich naprawia.

Szukaj po polsku: pułapki programowania asynchronicznego · zakleszczenie w async · rust async pitfalls · tokio blocking in async