An approach to solving FutureLock

⚓ Rust    📅 2025-12-31    👤 surdeus    👁️ 2      

surdeus

A few months ago, Oxide computer published 609 - Futurelock / RFD / Oxide , identifying a rust async pitfall known as "FutureLock".

I've been thinking about this, and also the issue of cancellation safety (something Oxide have also written excellently about: 400 - Dealing with cancel safety in async Rust / RFD / Oxide ).

When writing async rust code, I've often ended up needing a single task to react to multiple async inputs. For example, a server that reads/writes a TcpStream, and also an mpsc channel. One can use the tokio::select macro in a loop to implement such a task, reacting to whatever input becomes ready.

However, any code called from a select! arm must be cancellation safe, something which is not captured by the rust type system.

I therefore propose aselect: GitHub - avl/aselect: Less error-prone (in some ways) alternative to tokio::select .
It's a construct similar to tokio select, but it can be used as a stream. Meaning, you can await multiple futures, with shared state, without having to cancel futures in normal operation.

Feedback welcome!

1 post - 1 participant

Read full topic

🏷️ Rust_feed