Samyak Sarnayak

@samyaks

Amit Mandal

@notashes

Cancelling your future in tokio: cancellation in async rust

Submitted Mar 13, 2026

Summary

  • Async rust is performant, but there are pitfalls. The ideas behind async rust are quite simple, but it can lead to hard-to-debug issues.
  • In this talk, we’ll introduce the idea of cancellation in async rust and show why it can be a source of bugs. We’ll explain terms like cancellation-safety and different patterns of cancelling async work.
  • We then take the example of DataFusion and show how cancellation can be achieved even with CPU-heavy futures. During this, we introduce the concept of tokio’s task scheduling budgeting.
  • We show two practical cancellation bugs we faced in production:
    • Issue #1: A task kept running even after cancelling it.
    • Issue #2: We saw a deadlock (tasks hanging), even though there was only one tokio mutex and it was unlocked!

Outline

  • Brief intro to async: a future is just a state machine (5 mins)
  • Cancelling synchronous programs: can we kill a thread? (2 mins)
  • Cancelling rust futures: cancel-safety, patterns of cancellation (5 mins)
  • Cancelling cpu-heavy futures: introduce tokio-budgeting. DataFusion as an example of this. (5 mins)
  • Issue #1 (6-7 mins)
  • Issue #2 (6-7 mins)

Takeaways

  • Best-practices to follow when cancelling async rust. The compiler isn’t as helpful in async rust, so devs need to exercise more caution.
  • Be careful around Arcs. You could have unpredictable drops even without a GC.

Speaker bio

Samyak and Amit work on a rust-based OLAP query engine at e6data. We have encountered these problems while re-writing our execution engine from Java to Rust (using DataFusion).

Comments

{{ gettext('Login to leave a comment') }}

{{ gettext('Post a comment…') }}
{{ gettext('New comment') }}
{{ formTitle }}

{{ errorMsg }}

{{ gettext('No comments posted yet') }}

Hosted by

A community of Rust language contributors and end-users from Bangalore. We have presence on the following telegram channels https://t.me/RustIndia https://t.me/fpncr LinkedIn: https://www.linkedin.com/company/rust-india/ more