Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Tokio Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-tokio-knowledge-patch)
---
name: tokio-knowledge-patch
description: Tokio
version: "1.54.1"
license: MIT
metadata:
author: Nevaberry
---
# Tokio knowledge patch
Load this skill when upgrading Tokio or working with its runtime, tasks,
synchronization, I/O, networking, processes, signals, or companion crates.
Use the quick reference below for common compatibility decisions and the
topic files for detailed behavior, feature gates, examples, and release attribution.
## Reference index
| Reference | Topics |
| --- | --- |
| [Compatibility and upgrade floors](references/compatibility.md) | Rust and dependency requirements, Cargo feature migrations, upgrade fixes, WebAssembly |
| [Async I/O and filesystem](references/io-and-filesystem.md) | AsyncFd, readiness, buffers, adapters, file ownership and timestamps, unstable io_uring |
| [Networking, processes, and signals](references/networking-process-signals.md) | Socket conversion and options, Unix sockets and pipes, peer credentials, child processes, signals |
| [Runtime, tasks, and scheduling](references/runtime-and-tasks.md) | Runtime configuration, local tasks, cooperative polling, joins, metrics, tracing, unstable hooks and dumps, timers |
| [Synchronization and channels](references/synchronization.md) | Broadcast, mpsc, watch, oneshot, Notify, SetOnce, semaphores, reader limits |
| [Companion crates](references/tokio-util-and-stream.md) | Framing, I/O adapters, cancellation, task collections, delay queues, stream batching and timers |
## Breaking changes and deprecations
### Toolchain and runtime migration
Tokio 1.54 and tokio-util 0.7.20 require Rust 1.85 or later.
Upgrade the toolchain before moving to the Tokio 1.54 line.
Earlier compiler floors and dependency requirements are in the compatibility reference.
The unstable alternate multi-threaded runtime was removed.
Switch to the regular multi-threaded runtime if code selected the alternate scheduler.
### Descriptor registration and socket conversion
Tokio 1.51.6, 1.53.3, and 1.54 add `AsyncFd::register(fd)` and
`AsyncFd::register_with_interest(fd, interest)`. Migrate calls to the deprecated
`new`, `with_interest`, `try_new`, and `try_with_interest` methods to these APIs.
Passing a blocking socket to Tokio's socket `from_std` conversions can panic.
Set the standard-library socket to nonblocking mode before converting it inside the runtime.
`tokio::net::TcpStream::set_linger` and `tokio::net::TcpSocket::set_linger`
are deprecated. For an abortive TCP close, `stream.set_zero_linger()?`
requests that behavior before closing; closing can discard unsent data and reset
the connection at the peer.
### Positive settings and acquisition limits
- `tokio::runtime::Builder::global_queue_interval(0)` panics; pass a positive number of scheduler ticks.
- `tokio::runtime::Builder::event_interval(0)` panics; pass a positive interval.
- In Tokio 1.54, `Builder::max_io_events_per_tick` panics on zero.
- Tokio 1.54 requires positive sizes for `File::set_max_buf_size`, `BufReader`
and `BufStream` capacities, in-memory pipe capacity, and both buffers passed
to `copy_bidirectional_with_sizes`.
- Tokio 1.51.5 and 1.53.2 add an acquisition check against `Semaphore::MAX_PERMITS`;
keep requested permit counts within the limit.
- Starting in 1.47.5, pass a positive reader limit to
`tokio::sync::RwLock::with_max_readers(value, max_readers)`.
### Blocking and runtime entry
`tokio::task::block_in_place` panics while a `LocalSet` is being polled or dropped.
Move blocking work that can run on another thread to `tokio::task::spawn_blocking`.
`runtime::EnterGuard` is `!Send`. Drop guards on the thread that entered the runtime
and in reverse order when entries are nested; dropping them out of order panics.
### Output and listener lifetime
Writes through multiple `tokio::io::stdout()` handles can be reordered.
Serialize writes through one handle when their order matters.
Signal listeners retain the `Option` return type on `recv().await` and only yield
`Some(())`. A receive stays pending between signals, so listener loops need a
separate exit condition.
## Runtime and task quick reference
### Composing and joining work
`tokio::time::timeout`, `tokio::join!`, and `tokio::select!` accept `IntoFuture`
values directly, without an explicit `.into_future()` conversion.
Put `biased;` before branches in `tokio::join!` or `tokio::try_join!` to poll
them in declaration order.
`set.join_all().await` consumes a `tokio::task::JoinSet` and collects outputs
in completion order. A join error makes it panic and aborts remaining tasks.
Use a `join_next().await` loop to handle join errors individually.
`JoinSet` also implements `Extend` for spawnable futures; call `extend` within a runtime.
When awaiting a `JoinHandle` completes, Tokio has already dropped the task's future.
This also applies when awaiting the handle after calling `abort()`.
### Cooperative work
Use `tokio::task::consume_budget().await` in work loops to yield when the task
exhausts its cooperative budget. Wrap a future that does its own polling without
accounting for Tokio's budget in `tokio::task::coop::cooperative(future).await`.
In custom polls, call `tokio::task::coop::poll_proceed(cx)` before attempting work.
Propagate `Poll::Pending` when the budget is exhausted. Call `made_progress()` on
the returned guard after making progress so dropping the guard keeps the budget charge.
`tokio::select!` can yield before polling branches when the budget is exhausted,
even if a branch is ready. `watch::Receiver::changed()` and
`broadcast::Receiver::recv()` also participate in cooperative scheduling.
### Local execution and diagnostics
`tokio::runtime::LocalRuntime` is available in stable builds with the `rt` feature.
Code using `--cfg tokio_unstable` solely for `LocalRuntime` can drop that flag.
Call `tokio::task::spawn_local` inside `block_on` for a task capturing `!Send` state.
Use `tokio::task::id()` inside a task and `JoinHandle::id()` from spawning code
to correlate activity. Use `tokio::task::try_id()` if the caller may be outside a task.
Treat `RuntimeMetrics::num_alive_tasks()` as an estimate while tasks are being
spawned or completed concurrently.
Starting in Tokio 1.54, `tokio::runtime::worker_index()` is available without
`--cfg tokio_unstable`; use a worker's index to correlate work with per-worker metrics.
Runtime task hooks and task dumps remain unstable guidance in the runtime reference.
### Paused time
A running `spawn_blocking` task suppresses automatic clock advancement on a paused
runtime. Finish blocking work before relying on auto-advance to drive timers in tests.
Tokio 1.51.6 and 1.53.3 fix premature clock advancement on a paused current-thread
runtime when I/O wakes a task; the fix is also in 1.54.
## Synchronization quick reference
### Closed channels and outstanding permits
After `Receiver::close()`, an mpsc receiver's `try_recv()` returns
`TryRecvError::Disconnected` once buffered messages are drained and outstanding
permits are released, even if a sender handle remains alive.
With no queued messages but an outstanding send permit, a closed bounded channel's
`try_recv()` returns `TryRecvError::Empty` because the permit can still send.
For `recv_many` with a positive limit, zero means closed and drained, even if the
output vector still holds messages from previous calls. In synchronous code,
`receiver.blocking_recv_many(&mut buffer, limit)` appends up to `limit` messages
to a `Vec` and returns the number received.
`broadcast::Sender::new(capacity)` starts closed because it has no receivers.
Call `sender.subscribe()` to open it for delivery. Use `sender.closed().await`
to wait until there are no broadcast receivers. A `broadcast::WeakSender` allows
the send side to close when the last strong sender is dropped.
### Notification, publication, and semaphore guards
`Arc<Notify>::notified_owned()` returns an `OwnedNotified` without a borrow lifetime.
Use `notify.clone().notified_owned()` to move the wait into a spawned task while
keeping your own `Arc`. `Notify::notify_last()` wakes the most recently queued waiter.
`tokio::sync::SetOnce<T>` publishes a value with `set`; readers wait with `wait().await`.
`SetOnce::wait()` is cancellation-safe: if another `tokio::select!` branch wins,
a later call can still observe the published value.
Tokio 1.54 adds blocking semaphore acquisition. In synchronous code, use
`let permit = semaphore.blocking_acquire()?;` to hold a permit until the guard drops.
Use `permit.split(n)` to transfer held permits into another guard and
`permit.merge(other)` to combine guards from the same semaphore.
## I/O quick reference
`AsyncFd::try_io` and `try_io_mut` attempt a nonblocking operation for one readiness
interest. They return `WouldBlock` without cached readiness or if the operation
would block, and clear cached readiness when the operation returns `WouldBlock`.
In Tokio 1.54, accepted sockets start with both read and write readiness;
an immediate read after accepting can still return `WouldBlock`.
`tokio::io::copy_buf` participates in cooperative scheduling and flushes the writer
when the reader stalls in Tokio 1.54.
With `io-util`, `tokio::io::simplex(capacity)` creates read and write halves of a
bounded in-memory `SimplexStream` for one-way byte flow.
`tokio::fs::File::try_clone().await` preserves the `set_max_buf_size` limit.
Tokio 1.54 adds `tokio::fs::File::set_modified` and `File::set_times` with
`tokio::fs::FileTimes` for file timestamps.
Select unstable task dumps and io_uring with the `taskdump` and `io-uring` Cargo
features and continue building with `RUSTFLAGS="--cfg tokio_unstable"`.
The I/O reference details supported io_uring operations and fallback behavior.
## Companion crate quick reference
Use `tokio_util::io::write_all_vectored` when every buffer in a vectored write must be sent;
a single `write_vectored` call can consume only part of the buffers.
`tokio_util::io::read_exact_arc` and `write_all_vectored` retry operations returning
`std::io::ErrorKind::Interrupted`.
`LengthDelimitedCodec::set_max_frame_length` caps the requested limit to what the
configured length field can represent. Choose a wider length field for a higher limit.
Use tokio-util 0.7.20 or later when relying on `DelayQueue::peek()` for deadline ordering.
`CancellationToken::run_until_cancelled` favors the token when polling races with
cancellation. `token.run_until_cancelled_owned(work).await` can take ownership of it.
`StreamMap::next_many` appends up to `limit` `(key, item)` pairs to a caller-provided
vector and returns the number appended; use `poll_next_many` from a custom `poll`.
`ChunksTimeout::into_remainder` recovers buffered items when stopping the adapter.
`StreamExt::chunks_timeout` can be constructed outside a Tokio runtime; poll the
adapter on a runtime with time enabled.