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-nevaberry-plugins)
---
name: tokio-knowledge-patch
description: Tokio
version: "1.54.1"
license: MIT
metadata:
author: Nevaberry
---
# Tokio compatibility guidance
Load this skill when upgrading Tokio or working with its runtime, tasks,
synchronization, I/O, networking, processes, signals, or companion crates.
Use the topic references for API details, examples, and version-specific behavior.
## Topic index
| Reference | Topics |
| --- | --- |
| [Compatibility and upgrade floors](references/compatibility.md) | Toolchains, dependencies, Cargo features, target support, upgrade fixes |
| [Async I/O and filesystem](references/io-and-filesystem.md) | Descriptor registration, buffers, adapters, files, vectored I/O, unstable io_uring |
| [Networking, processes, and signals](references/networking-process-signals.md) | Socket readiness and options, Unix pipes and credentials, child processes, signals |
| [Runtime, tasks, and scheduling](references/runtime-and-tasks.md) | Runtime construction, task sets, macros, cooperative polling, timers, metrics, unstable hooks |
| [Synchronization and channels](references/synchronization.md) | Broadcast, mpsc, oneshot, watch, notification, semaphores, single-assignment values |
| [Companion crates: `tokio-util` and `tokio-stream`](references/tokio-util-and-stream.md) | Framing, I/O helpers, cancellation, task collections, delay queues, stream adapters |
## Breaking changes and deprecations
### Toolchain and registration migrations
Tokio 1.54 requires Rust 1.85; upgrade the toolchain before moving to that line.
`tokio-util` 0.7.20 also requires Rust 1.85 or later.
Migrate calls to the deprecated `AsyncFd` methods `new`, `with_interest`,
`try_new`, and `try_with_interest` to `AsyncFd::register(fd)` and
`AsyncFd::register_with_interest(fd, interest)`. The I/O reference preserves
the older APIs' descriptor-recovery behavior and the registration API versions.
`tokio::net::TcpStream::set_linger` and `tokio::net::TcpSocket::set_linger`
are deprecated. Call `stream.set_zero_linger()?` on a `tokio::net::TcpStream`
before closing it to request an abortive close. Closing can discard unsent
data and reset the connection at the peer.
### Socket conversion and positive limits
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::runtime::Builder::global_queue_interval(0)` and
`tokio::runtime::Builder::event_interval(0)` panic. Pass positive intervals.
`Builder::max_io_events_per_tick` also panics on zero in Tokio 1.54.
The separate `Builder::max_io_events_per_busy_tick` limits events processed
per tick while the scheduler is busy.
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`.
Keep requested semaphore acquisitions within `Semaphore::MAX_PERMITS`.
Pass a positive reader limit to `tokio::sync::RwLock::with_max_readers(value, max_readers)`.
### Runtime entry and blocking restrictions
The unstable alternate multi-threaded runtime was removed. Switch to the
regular multi-threaded runtime if your code selected the alternate scheduler.
`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. Out-of-order drops panic.
### Upgrade fixes tied to affected code
- On the 1.39 line, use 1.39.3 for the timer-wheel reversion, the `select!`
temporary-lifetime fix, and restored Unix abstract-namespace socket support.
- For broadcasting `Send + !Sync` values, use 1.42.1; on the 1.44 line use
1.44.2 or later, and on the 1.38 line upgrade to 1.38.2.
- On the 1.52 line, use 1.52.1 or later for the `spawn_blocking` hang fix.
- Use 1.53.1 when building Windows signal support with Tokio's minimum
supported Rust version; 1.53.0 used `OnceLock::wait`, requiring a newer compiler.
## Tasks, runtimes, and cooperative polling
### Local tasks and runtime macros
`tokio::runtime::LocalRuntime` is stable with the `rt` feature. Code that used
`--cfg tokio_unstable` solely for `LocalRuntime` can drop that flag.
Call `tokio::task::spawn_local` inside `block_on` for tasks capturing `!Send` state.
The runtime macro's `flavor = "local"` remains unstable in this guidance:
use the `rt` and `macros` features with `--cfg tokio_unstable`.
The unstable `unhandled_panic` option can be set in `#[tokio::main]`
and `#[tokio::test]` to configure the response to an unhandled task panic.
`tokio::time::timeout`, `tokio::join!`, and `tokio::select!` accept `IntoFuture`
values directly. Put `biased;` before branches in `tokio::join!` or
`tokio::try_join!` to poll them in declaration order.
### Task sets and completion
`set.join_all().await` consumes a `tokio::task::JoinSet` and collects results
in completion order. A join error makes it panic and abort the remaining tasks.
Use a `join_next().await` loop to handle join errors individually.
`JoinSet` implements `Extend` for spawnable futures. Call `extend` within a
runtime to spawn an iterator's futures into an existing set.
When awaiting a `JoinHandle` completes, the task's future has already been
dropped, including when awaiting the handle after `abort()`.
### Cooperative work loops
Use `tokio::task::consume_budget().await` in work loops to yield when the task
exhausts its cooperative budget. Wrap a future that polls without accounting
for Tokio's budget in `tokio::task::coop::cooperative(future).await`.
In custom polls, call `tokio::task::coop::poll_proceed(cx)` before work.
Propagate `Poll::Pending` when the budget is exhausted. After making progress,
call `made_progress()` on the returned guard so dropping it keeps the charge.
`tokio::select!` can yield before polling branches after exhausting the budget,
even if a branch is ready. `watch::Receiver::changed()` and
`broadcast::Receiver::recv()` also participate in cooperative scheduling.
### Paused clocks and runtime diagnostics
A running `spawn_blocking` task suppresses automatic clock advancement on a
paused runtime. Finish blocking work before relying on auto-advance in tests.
Tokio 1.51.6, 1.53.3, and 1.54 fix premature clock advancement when I/O wakes
a task on a paused current-thread runtime.
`RuntimeMetrics::num_alive_tasks()` is stable; treat it as an estimate while
tasks are spawned or completed concurrently. `global_queue_depth()` counts
tasks queued in the runtime's global scheduler queue.
`worker_total_busy_duration(worker)`, `worker_park_count(worker)`, and
`worker_unpark_count(worker)` are stable per-worker metrics.
`tokio::runtime::worker_index()` is available without `--cfg tokio_unstable`
starting in Tokio 1.54. Use it to correlate work with per-worker metrics.
Use `tokio::task::id()` and `JoinHandle::id()` to correlate task activity;
use `tokio::task::try_id()` when the caller may be outside a task.
The runtime reference also covers unstable lifecycle hooks, poll callbacks,
histograms, task dumps, and their version-specific behavior.
## Synchronization and channel state
`tokio::sync::SetOnce<T>` publishes a value with `set` and lets readers wait
with `wait().await`. Its `wait()` is cancellation-safe: after another
`tokio::select!` branch wins, a later wait can still observe the value.
`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. `notify_waiters()` takes precedence when it and a
single-waiter notification can both complete a `Notified` future.
`watch::Receiver::mark_unchanged()` marks the current version seen without
borrowing it. The next `changed().await` waits for a new version while open.
`watch::Ref::has_changed()` reports whether the borrowed value was new to
the receiver when acquired.
Use `receiver.blocking_recv_many(&mut buffer, limit)` in synchronous code
to append up to `limit` messages to a `Vec`. With a positive limit, zero
means closed and drained. On closed bounded mpsc channels, `try_recv()` can
still return `TryRecvError::Empty` when no messages are queued and an
outstanding permit can send;
after draining and releasing permits, it returns `TryRecvError::Disconnected`.
`broadcast::Sender::new(capacity)` starts closed because there are no receivers;
call `sender.subscribe()` to open delivery. `sender.closed().await` waits for
no receivers. `sender.downgrade()` creates a `broadcast::WeakSender`; it allows
closure when the last strong sender drops. `weak.upgrade()` returns `Option<Sender<T>>`.
Tokio 1.54 adds `semaphore.blocking_acquire()?` for synchronous code.
`permit.split(n)` transfers held permits to a second guard; `permit.merge(other)`
combines guards from the same semaphore for release together on drop.
## I/O, files, networking, and signals
With `io-util`, `tokio::io::simplex(capacity)` creates bounded in-memory read
and write halves for one-way byte flow. Zero-length memory-stream reads and
writes complete immediately in Tokio 1.54, even when nonempty I/O would wait.
`AsyncFd::try_io` and `try_io_mut` attempt a nonblocking operation for one
readiness interest. They return `WouldBlock` without cached readiness or when
the operation would block, clearing cached readiness in the latter case.
`tokio::fs::File::try_clone().await` preserves the `set_max_buf_size` limit;
inspect it with `max_buf_size()`. `tokio::fs::File::set_modified` sets modification
time, and `File::set_times` with `tokio::fs::FileTimes` sets timestamps together.
`tokio::io::copy_buf` participates in cooperative scheduling and flushes the
writer when the reader stalls. Writes through multiple `tokio::io::stdout()`
handles can be reordered; serialize through one handle when order matters.
Accepted sockets start with both read and write readiness in Tokio 1.54;
an immediate read can still return `WouldBlock`. Endpoints from `UnixStream::pair`
and `UnixDatagram::pair` start with write readiness.
Signal `recv().await` retains its `Option` return type
and only yields `Some(())`, so listener loops need a separate exit condition.
Select unstable task dumps and io_uring with the `taskdump` and `io-uring`
Cargo features and continue using `RUSTFLAGS="--cfg tokio_unstable"`.
The references distinguish supported filesystem operations and fallbacks.
## Companion crates
Use `tokio_util::io::write_all_vectored` when every buffer must be sent;
one `write_vectored` call can consume only part. `write_all_vectored` and
`tokio_util::io::read_exact_arc` retry
`std::io::ErrorKind::Interrupted` operations in `tokio-util` 0.7.20.
`LengthDelimitedCodec` can encode `&[u8]` directly. Its
`LengthDelimitedCodec::set_max_frame_length` caps limits to the configured
length field's range; choose a wider field when the protocol needs more.
`CancellationToken::run_until_cancelled` favors the token when polling races
with cancellation starting in 0.7.16. `token.run_until_cancelled_owned(work).await`
can take ownership of the token. `JoinMap` supports keyed tasks; `JoinQueue`
collects task results, and probing it with `try_join_next()` preserves an
existing waiter's waker starting in 0.7.19.
Use `DelayQueue::peek()` to inspect the next entry's key without removal;
use 0.7.20 or later when relying on deadline ordering. Removing the last item,
resetting to an expired deadline, and `DelayQueue::clear()` wake a pending
consumer in the versions documented in the companion reference.
`StreamMap::next_many` appends up to `limit` `(key, item)` pairs and returns
the count; `poll_next_many` supports custom polling. `StreamNotifyClose`
supplies one final `None` item to identify a closed source in a `StreamMap`.
`ChunksTimeout::into_remainder` recovers items buffered for the next chunk.