Fly.ioTutorial
The Tokio Upgrade from 0.2 to 1.x
Summary
Fly.io’s Rust-based load balancer handles almost all of its traffic and stands on Tokio and Hyper, motivating an upgrade from Tokio 0.2 to 1.0. The team waited to upgrade until related crates including hyper, reqwest, async-compression, tokio-io-timeout, tokio-tungstenite, and sentry were ready; after a few weeks, most of the ecosystem had upgraded. The migration foregoes Tokio’s Stream implementations pending stabilization in the standard library, relaxes mutable-access requirements, changes AsyncRead and AsyncWrite polling to return Result<()>, and requires more explicit pinning for !Unpin futures. Because runtime::Handle lacked block_on, the team worked around the restriction with Arc; standard TcpListener values also required set_nonblocking(true) before TcpListener::from_std. Other changes included renamed APIs and revised Hyper WebSocket upgrades, and the author says the major upgrade was not hard.
Context
Fly.io wanted to keep its Rust software up to date and gain access to related crate upgrades after Tokio 0.3 and 1.0 were announced. Its load balancer depends on Tokio, Hyper, and several related crates, so the team waited until much of that ecosystem was ready.
Approach / What changed
The upgrade notes identify Tokio 0.2-to-1.0 API differences and show workarounds for changed Stream support, relaxed mutability requirements, new AsyncRead and AsyncWrite traits, additional pinning, the missing runtime::Handle::block_on method, listener nonblocking requirements, and Hyper WebSocket upgrades.
Takeaways
Tokio 1.0 foregoes Stream implementations until standard-library stabilization; tokio-stream supplies implementations for TcpListener, Interval, and more.
AsyncRead::poll_read and AsyncWrite::poll_write now return Result<()> rather than byte counts, with ReadBuf::filled() used to calculate bytes read when needed.
A standard listener passed to tokio::net::TcpListener::from_std must be set nonblocking first; otherwise accepting connections can hang.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.