Skip to content

rt: improve spawn_blocking scalability with sharded queue - #7757

Merged
Darksonn merged 2 commits into
tokio-rs:masterfrom
alex:claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf
Apr 10, 2026
Merged

Darksonn merged 2 commits into
tokio-rs:masterfrom
alex:claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf

Conversation

@alex

@alex alex commented Dec 4, 2025 •

Copy link
Copy Markdown
Contributor

The blocking pool's task queue was protected by a single mutex, causing severe contention when many threads spawn blocking tasks concurrently. This resulted in nearly linear degradation: 16 concurrent threads took ~18x longer than a single thread.

Replace the single-mutex queue with a sharded queue that distributes tasks across 16 lock-protected shards. The implementation adapts to concurrency levels by using fewer shards when thread count is low, maintaining cache locality while avoiding contention at scale.

Benchmark results (spawning 100 batches of 16 tasks per thread):

Concurrency Before After Improvement
1 thread 13.3ms 17.8ms +34%
2 threads 26.0ms 20.1ms -23%
4 threads 45.4ms 27.5ms -39%
8 threads 111.5ms 20.3ms -82%
16 threads 247.8ms 22.4ms -91%

The slight overhead at 1 thread is due to the sharded infrastructure, but this is acceptable given the dramatic improvement at higher concurrency where the original design suffered from lock contention.

(Notwithstanding that this shows as a commit from claude, every line is human reviewed. If there's a mistake, it's Alex's fault.)

Closes #2528.

@alex
alex force-pushed the claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf branch 3 times, most recently from 9537dda to 016f6ca Compare December 4, 2025 00:19
@alex

alex commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

(FreeBSD failures look unrelated.)

@ADD-SP ADD-SP added A-tokio Area: The main tokio crate M-blocking Module: tokio/task/blocking T-performance Topic: performance and benchmarks labels Dec 4, 2025
@ADD-SP ADD-SP added S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. and removed S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. labels Dec 4, 2025
Comment thread tokio/src/runtime/blocking/pool.rs Resolved
@alex
alex force-pushed the claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf branch 2 times, most recently from f4416fb to 21ff5ce Compare December 4, 2025 17:36
@martin-g

martin-g commented Dec 4, 2025

Copy link
Copy Markdown
Member

Please rebase to latest master to get the fix for the FreeBSD failures.

@alex
alex force-pushed the claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf branch from 21ff5ce to 694fa6b Compare December 4, 2025 17:39
Comment thread tokio/src/runtime/blocking/pool.rs Resolved
@alex
alex force-pushed the claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf branch from 694fa6b to edd5e10 Compare December 5, 2025 12:37
Comment thread tokio/src/runtime/blocking/pool.rs Resolved
@alex
alex force-pushed the claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf branch from edd5e10 to 126cb78 Compare December 6, 2025 02:06
Comment thread tokio/src/runtime/blocking/pool.rs Resolved
@ADD-SP ADD-SP added S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. and removed S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. labels Dec 7, 2025
Comment on lines +117 to +120
// Update max_shard_pushed BEFORE pushing the task.
self.max_shard_pushed.fetch_max(index, Release);

self.shards[index].push(task);

@ADD-SP ADD-SP Dec 8, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the Release ordering, compiler might reorder the self.shards[index].push(task) and fetch_max, which means that the .push(task) might be sequenced-before the fetch_max.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. (I hate atomic orderings :-/) AcqRel I think is what we want.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong. Consider the following scenario:

Thread A                   Thread B            Thread C
                                               preferred_shard = 0
                           preferred_shard = 1
max_shard_pushed = 0
shards[0].push(_)
condvar.notify_one()
                           wakes up ...
                           max_shard = 0
max_shard_pushed = 1
shards[1].push(_)
condvar.notify_one()
                                               wakes up ...
                                               max_shard = 1
                                               shards[0].pop() = Some
                           shards[0].pop() = None

In this case, Thread B does not check shards[1] because it read max_shard with the value of zero. This means that two tasks were spawned, but only one gets picked up.

Well, I guess in principle Thread C will see the second task after it finishes executing the first one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it's always the case that if a push happens concurrently with a pop that the pop might miss it, and we'll have to "fall back" to catching it in the wait_for_task loop.

I think in principle we could address this one by reloading max_shard_pushed, but of course you can still have a race condition.

In the scenario you've got here, what would happen is that after thread B returns None from pop, it'll go wait_for_task and then the task will get picked up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it's always the case that if a push happens concurrently with a pop that the pop might miss it, and we'll have to "fall back" to catching it in the wait_for_task loop.

Your notify_one() call ensures that for every push(), there will be a subsequent call to pop() that is not concurrent and hence guaranteed to see the pushed message. So there's at least one thread that's guaranteed to pick up each message.

If we imagine that the max_shard_pushed logic was removed, then Thread B would in fact be guaranteed to see the message in shards[1].

  • shards[1].push(_) on A happens-before shards[0].pop() = Some on thread C because thread C is the thread waken up by the second notify_one() call.
  • shards[0].pop() = Some on thread C happens-before shards[0].pop() = None on thread B, since otherwise thread B would have gotten Some when calling pop().
  • After shards[0].pop() = None, thread B would attempt to call shards[1].pop()

So by this logic, the shards[1].pop() call would in fact happen after shards[1].push(_), and is hence guaranteed to see the message that was pushed.

@alex
alex force-pushed the claude/improve-spawn-blocking-perf-01A5VqgjoFsxUcvmP6eAjdTf branch from 855e269 to 046d5c6 Compare December 8, 2025 14:12
Comment on lines +181 to +191
// Acquire the condvar mutex before waiting
let guard = self.condvar_mutex.lock();

// Double-check shutdown and tasks after acquiring lock, as state may
// have changed while we were waiting for the lock
if self.is_shutdown() {
return WaitResult::Shutdown;
}
if let Some(task) = self.pop(preferred_shard) {
return WaitResult::Task(task);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we attempt to acquire the shard lock while holding the condvar lock, this is the nested locking pattern. In general, we should avoid this pattern as it is error-prone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is there a preferred pattern to avoid the nested locking?

In this case we want to ensure that when we wait for a notification, there wasn't already a task that's made pending concurrently.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested locking is fine as long as locks are always taken in the same order.

@ADD-SP ADD-SP added the S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. label Dec 11, 2025
@alex

alex commented Dec 15, 2025

Copy link
Copy Markdown
Contributor Author

(I don't think the netlify failures are related)

alex added a commit to alex/tokio that referenced this pull request Apr 12, 2026
…tion

The multi-threaded scheduler's inject queue was protected by a single
global mutex (shared with idle coordination state). Every remote task
spawn — any spawn from outside a worker thread — acquired this lock,
serializing concurrent spawners and limiting throughput.

This change introduces `inject::Sharded`, which splits the inject queue
into up to 8 independent shards, each an existing `Shared`/`Synced`
pair with its own mutex and cache-line padding.

Design:
- Push: each thread is assigned a home shard on first push (via a
  global counter) and sticks with it. This keeps consecutive pushes
  from one thread cache-local while spreading distinct threads across
  distinct locks.
- Pop: workers rotate through shards starting at their own index,
  skipping empty shards via per-shard atomic length. pop_n drains from
  one shard at a time to keep critical sections bounded.
- Shard count: capped at 8 (and 1 under loom). Contention drops off
  steeply past a handful of shards, and is_empty()/len() scan all
  shards in the worker hot loop.
- is_closed: a single Release atomic set after all shards are closed,
  so the shutdown check stays lock-free.

Random shard selection via context::thread_rng_n (as used in tokio-rs#7757 for
the blocking pool) was measured and found to be 20-33% slower on
remote_spawn at 8+ threads. The inject workload is a tight loop of
trivial pushes where producer-side cache locality dominates: with RNG,
a hot thread bounces between shard cache lines on every push; with
sticky assignment it stays hot on one mutex and list tail. RNG did win
slightly (5-9%) on single-producer benchmarks where spreading tasks
lets workers pop in parallel, but not enough to offset the regression
at scale.

The inject state is removed from the global Synced mutex, which now
only guards idle coordination. This also helps the single-threaded
path since remote pushes no longer contend with worker park/unpark.

Results on remote_spawn benchmark (12,800 no-op tasks, N spawner
threads, 64-core box):

  threads   before    after    improvement
  1         9.38 ms   7.33 ms  -22%
  2        14.94 ms   6.64 ms  -56%
  4        23.69 ms   5.34 ms  -77%
  8        34.81 ms   4.69 ms  -87%
  16       32.33 ms   4.54 ms  -86%
  32       30.37 ms   4.73 ms  -84%
  64       26.59 ms   5.34 ms  -80%

rt_multi_threaded benchmarks: spawn_many_local -8%, spawn_many_remote_idle
-7%, yield_many -1%, rest neutral.

Developed in conjunction with Claude.
alex added a commit to alex/tokio that referenced this pull request Apr 14, 2026
…tion

The multi-threaded scheduler's inject queue was protected by a single
global mutex (shared with idle coordination state). Every remote task
spawn — any spawn from outside a worker thread — acquired this lock,
serializing concurrent spawners and limiting throughput.

This change introduces `inject::Sharded`, which splits the inject queue
into up to 8 independent shards, each an existing `Shared`/`Synced`
pair with its own mutex and cache-line padding.

Design:
- Push: each thread is assigned a home shard on first push (via a
  global counter) and sticks with it. This keeps consecutive pushes
  from one thread cache-local while spreading distinct threads across
  distinct locks.
- Pop: workers rotate through shards starting at their own index,
  skipping empty shards via per-shard atomic length. pop_n drains from
  one shard at a time to keep critical sections bounded.
- Shard count: capped at 8 (and 1 under loom). Contention drops off
  steeply past a handful of shards, and is_empty()/len() scan all
  shards in the worker hot loop.
- is_closed: a single Release atomic set after all shards are closed,
  so the shutdown check stays lock-free.

Random shard selection via context::thread_rng_n (as used in tokio-rs#7757 for
the blocking pool) was measured and found to be 20-33% slower on
remote_spawn at 8+ threads. The inject workload is a tight loop of
trivial pushes where producer-side cache locality dominates: with RNG,
a hot thread bounces between shard cache lines on every push; with
sticky assignment it stays hot on one mutex and list tail. RNG did win
slightly (5-9%) on single-producer benchmarks where spreading tasks
lets workers pop in parallel, but not enough to offset the regression
at scale.

The inject state is removed from the global Synced mutex, which now
only guards idle coordination. This also helps the single-threaded
path since remote pushes no longer contend with worker park/unpark.

Results on remote_spawn benchmark (12,800 no-op tasks, N spawner
threads, 64-core box):

  threads   before    after    improvement
  1         9.38 ms   7.33 ms  -22%
  2        14.94 ms   6.64 ms  -56%
  4        23.69 ms   5.34 ms  -77%
  8        34.81 ms   4.69 ms  -87%
  16       32.33 ms   4.54 ms  -86%
  32       30.37 ms   4.73 ms  -84%
  64       26.59 ms   5.34 ms  -80%

rt_multi_threaded benchmarks: spawn_many_local -8%, spawn_many_remote_idle
-7%, yield_many -1%, rest neutral.

Developed in conjunction with Claude.
hawkw added a commit that referenced this pull request Apr 14, 2026
# 1.52.0 (April 14th, 2026)

## Added

- io: `AioSource::register_borrowed` for I/O safety support ([#7992])
- net: add `try_io` function to `unix::pipe` sender and receiver types
  ([#8030])

## Added (unstable)

- runtime: `Builder::enable_eager_driver_handoff` setting enable eager
  hand
  off of the I/O and time drivers before polling tasks ([#8010])
- taskdump: add `trace_with()` for customized task dumps ([#8025])
- taskdump: allow `impl FnMut()` in `trace_with`` instead of just `fn()`

  ([#8040])
- fs: support `io_uring` in `AsyncRead` for `File` ([#7907])

## Changed

- runtime: improve `spawn_blocking` scalability with sharded queue
  ([#7757])
- runtime: use `compare_exchange_weak()` in worker queue ([#8028])

## Fixed

- runtime: overflow second half of tasks when local queue is filled
  instead of
  first half ([#8029])

## Documented

- docs: fix typo in `oneshot::Sender::send` docs ([#8026])
- docs: hide #[tokio::main] attribute in the docs of `sync::watch`
  ([#8035])
- net: add docs on `ConnectionRefused` errors with UDP sockets ([#7870])

[#7757]: #7757
[#7870]: #7870
[#7907]: #7907
[#7992]: #7992
[#8010]: #8010
[#8025]: #8025
[#8026]: #8026
[#8028]: #8028
[#8029]: #8029
[#8030]: #8030
[#8035]: #8035
[#8040]: #8040
@hawkw hawkw mentioned this pull request Apr 14, 2026
hawkw added a commit that referenced this pull request Apr 14, 2026
# 1.52.0 (April 14th, 2026)

## Added

- io: `AioSource::register_borrowed` for I/O safety support ([#7992])
- net: add `try_io` function to `unix::pipe` sender and receiver types
  ([#8030])

## Added (unstable)

- runtime: `Builder::enable_eager_driver_handoff` setting enable eager
  hand off of the I/O and time drivers before polling tasks ([#8010])
- taskdump: add `trace_with()` for customized task dumps ([#8025])
- taskdump: allow `impl FnMut()` in `trace_with` instead of just `fn()`
  ([#8040])
- fs: support `io_uring` in `AsyncRead` for `File` ([#7907])

## Changed

- runtime: improve `spawn_blocking` scalability with sharded queue
  ([#7757])
- runtime: use `compare_exchange_weak()` in worker queue ([#8028])

## Fixed

- runtime: overflow second half of tasks when local queue is filled
  instead of first half ([#8029])

## Documented

- docs: fix typo in `oneshot::Sender::send` docs ([#8026])
- docs: hide #[tokio::main] attribute in the docs of `sync::watch`
  ([#8035])
- net: add docs on `ConnectionRefused` errors with UDP sockets ([#7870])

[#7757]: #7757
[#7870]: #7870
[#7907]: #7907
[#7992]: #7992
[#8010]: #8010
[#8025]: #8025
[#8026]: #8026
[#8028]: #8028
[#8029]: #8029
[#8030]: #8030
[#8035]: #8035
[#8040]: #8040
hawkw added a commit that referenced this pull request Apr 16, 2026
This reverts commit 1604bc3.

Unfortunately, this commit introduced a regression that causes programs
using `spawn_blocking` to hang (see #8056). To fix the regression, we
need to undo this change and publish a v1.52.1 release as soon as
possible.

In the future, we may wish to bring back a sharded queue for
`spawn_blocking` tasks, either based on the implementation added in
#7757 or a new one. However, since this is a substantial change to the
runtime internals, I think such a change should probably be done as an
unstable, opt-in `tokio::runtime::Builder` setting initially, so that we
don't regress existing users. I had hoped we could do this now, but
unfortunately, the sharded queue implementation from #7757 is kind of
tightly coupled with the rest of the `spawn_blocking` machinery and
cannot be easily swapped out --- and the hang still occurs with
`NUM_SHARDS` set to 1, so there isn't an easy way to turn it on and off.
Therefore, in the interest of getting a fix out ASAP, this is just a
simple revert.
hawkw added a commit that referenced this pull request Apr 16, 2026
This reverts commit 1604bc3.

Unfortunately, this commit introduced a regression that causes programs
using `spawn_blocking` to hang (see #8056). To fix the regression, we
need to undo this change and publish a v1.52.1 release as soon as
possible.

In the future, we may wish to bring back a sharded queue for
`spawn_blocking` tasks, either based on the implementation added in
#7757 or a new one. However, since this is a substantial change to the
runtime internals, I think such a change should probably be done as an
unstable, opt-in `tokio::runtime::Builder` setting initially, so that we
don't regress existing users. I had hoped we could do this now, but
unfortunately, the sharded queue implementation from #7757 is kind of
tightly coupled with the rest of the `spawn_blocking` machinery and
cannot be easily swapped out --- and the hang still occurs with
`NUM_SHARDS` set to 1, so there isn't an easy way to turn it on and off.
Therefore, in the interest of getting a fix out ASAP, this is just a
simple revert.

Fixes #8056
hawkw added a commit that referenced this pull request Apr 16, 2026
# 1.52.1 (April 16th, 2026)

## Fixed

- runtime: revert [#7757] to fix [a regression][#8056] that causes
  `spawn_blocking` to hang ([#8057])

[#7757]: #7757
[#8056]: #8056
[#8057]: #8057
hawkw added a commit that referenced this pull request Apr 16, 2026
# 1.52.1 (April 16th, 2026)

## Fixed

- runtime: revert [#7757] to fix [a regression][#8056] that causes
  `spawn_blocking` to hang ([#8057])

[#7757]: #7757
[#8056]: #8056
[#8057]: #8057
hawkw added a commit to oxidecomputer/omicron that referenced this pull request Apr 16, 2026
Commit #10272 updated our dependency on `oxide-tokio-rt` to v0.1.4 and
our `tokio` dependency to v1.52.0. This allowed us to pick up two of my
fixes for Tokio issues that have been a thorn in our side for a long
time, tokio-rs/tokio#7431 and tokio-rs/tokio#8010, which fix #8334 and
#9619, respectively. The nature of these fixes is described in greater
detail in #10272.

Unfortunately, #10272 had to be reverted (in #10279), since @iliana
discovered an unrelated regression in Tokio v1.52.0, tokio-rs/tokio#8056
(our issue #10277). This regression caused `spawn_blocking` to
occasionally hang, and was introduced in
tokio-rs/tokio@1604bc3 (PR
tokio-rs/tokio#7757).

I've since reverted this change upstream (tokio-rs/tokio#8057), and
published a patch release ([v1.52.1]), which fixes the regression.
Therefore, it is now once again safe to update our Tokio dependency to
pick up the other fixes. This commit does that. I've also confirmed that
the issue described in #10277 is no longer present in Tokio v1.52.1, as
demonstrated by the fact `cargo nextest run -p omicron-sled-agent
--stress-count 100 -- --exact artifact_store::test::issue_7796` now
succeeds without hanging once again.

Fixes #10272
alex pushed a commit to alex/tokio that referenced this pull request Apr 18, 2026
…ssion)

After tokio-rs#7757 the blocking pool uses `num_idle_threads` (a Relaxed atomic)
to decide between notifying an idle worker and spawning a new one, but
the counter is only decremented by a worker *after* `wait_for_task`
returns a `Task`. A spawner that races with the worker's transition can
read a stale positive value, take the notify-only path, and have its
notification delivered to a worker that is no longer idle. If the pool
then has no actually-idle workers (e.g. all workers are running blocking
tasks such as `rx.blocking_recv()`), the new task is stranded in the
queue indefinitely.

This is the hang observed by omicron's
`artifact_store::test::issue_7796` after its bump to tokio 1.52.0
(oxidecomputer/omicron#10277).

Fix the race by making the spawner's "notify an idle worker" decision
atomic with the worker's transition out of the idle state:

* `SharedQueue::try_claim_idle_and_notify` takes `condvar_mutex`, checks
  `num_idle_threads`, and if a slot exists decrements it *and* bumps
  `num_notify` before waking a worker.
* `SharedQueue::wait_for_task` is now responsible for the
  `num_idle_threads` counter: it increments on entry under
  `condvar_mutex`, decrements on the Timeout / Shutdown paths, and
  leaves the counter alone on the Task path (the spawner already
  released the slot as part of the claim). The spurious-pop path
  re-increments to stay consistent.
* `spawn_task` tries to claim an idle worker first; if no slot was
  available, it falls through to the shared-mutex spawn path with a
  re-check so a worker that parked during the interval can still be
  used.

The existing `task_blocking`, `rt_unstable_metrics`, and
`loom_blocking` suites pass. Running omicron's `issue_7796` 150 times
in a row now passes; prior to the fix the hang would reliably reproduce
within ~30–50 iterations.
eleboucher pushed a commit to eleboucher/towonel that referenced this pull request Apr 18, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | workspace.dependencies | minor | `1.51.1` → `1.52.1` |

---

### Release Notes

<details>
<summary>tokio-rs/tokio (tokio)</summary>

### [`v1.52.1`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.52.1): Tokio v1.52.1

[Compare Source](tokio-rs/tokio@tokio-1.52.0...tokio-1.52.1)

### 1.52.1 (April 16th, 2026)

#### Fixed

- runtime: revert [#&#8203;7757] to fix [a regression][#&#8203;8056] that causes `spawn_blocking` to hang ([#&#8203;8057])

[#&#8203;7757]: tokio-rs/tokio#7757

[#&#8203;8056]: tokio-rs/tokio#8056

[#&#8203;8057]: tokio-rs/tokio#8057

### [`v1.52.0`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.52.0): Tokio v1.52.0

[Compare Source](tokio-rs/tokio@tokio-1.51.1...tokio-1.52.0)

### 1.52.0 (April 14th, 2026)

#### Added

- io: `AioSource::register_borrowed` for I/O safety support ([#&#8203;7992])
- net: add `try_io` function to `unix::pipe` sender and receiver types ([#&#8203;8030])

#### Added (unstable)

- runtime: `Builder::enable_eager_driver_handoff` setting enable eager hand off of the I/O and time drivers before polling tasks ([#&#8203;8010])
- taskdump: add `trace_with()` for customized task dumps ([#&#8203;8025])
- taskdump: allow `impl FnMut()` in `trace_with` instead of just `fn()` ([#&#8203;8040])
- fs: support `io_uring` in `AsyncRead` for `File` ([#&#8203;7907])

#### Changed

- runtime: improve `spawn_blocking` scalability with sharded queue ([#&#8203;7757])
- runtime: use `compare_exchange_weak()` in worker queue ([#&#8203;8028])

#### Fixed

- runtime: overflow second half of tasks when local queue is filled instead of first half ([#&#8203;8029])

#### Documented

- docs: fix typo in `oneshot::Sender::send` docs ([#&#8203;8026])
- docs: hide #\[tokio::main] attribute in the docs of `sync::watch` ([#&#8203;8035])
- net: add docs on `ConnectionRefused` errors with UDP sockets ([#&#8203;7870])

[#&#8203;7757]: tokio-rs/tokio#7757

[#&#8203;7870]: tokio-rs/tokio#7870

[#&#8203;7907]: tokio-rs/tokio#7907

[#&#8203;7992]: tokio-rs/tokio#7992

[#&#8203;8010]: tokio-rs/tokio#8010

[#&#8203;8025]: tokio-rs/tokio#8025

[#&#8203;8026]: tokio-rs/tokio#8026

[#&#8203;8028]: tokio-rs/tokio#8028

[#&#8203;8029]: tokio-rs/tokio#8029

[#&#8203;8030]: tokio-rs/tokio#8030

[#&#8203;8035]: tokio-rs/tokio#8035

[#&#8203;8040]: tokio-rs/tokio#8040

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL21pbm9yIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/towonel/pulls/11
@alex alex mentioned this pull request Apr 18, 2026
3 of 4 tasks
alex pushed a commit to alex/tokio that referenced this pull request Apr 18, 2026
Public-API-only test that reproduces the hang described in
oxidecomputer/omicron#10277. Each iteration builds a fresh
current-thread runtime, runs a scenario modeled on omicron's
`ArtifactStore::writer` / `write_stream` pattern (transient writers
whose senders are dropped immediately, interleaved with persistent
writers whose blocking tasks park in `mpsc::Receiver::blocking_recv`),
and drains the persistent writers under a 1-second timeout.

Observed behaviour over 10 runs each:

  * pre-tokio-rs#7757 (1604bc3^) : pass (1.1s)
  * post-tokio-rs#7757, no fix   : fail on iteration 0-11 (1.2s), 10/10 reliable
  * post-tokio-rs#7757, with fix : pass (1.0s), 10/10 reliable

The test only uses the public tokio API (`tokio::runtime::Builder`,
`tokio::task::{spawn_blocking, JoinSet}`, `tokio::sync::mpsc`,
`tokio::time::timeout`).
alex added a commit to alex/tokio that referenced this pull request Apr 27, 2026
alex added a commit to alex/tokio that referenced this pull request Aug 1, 2026
Re-lands the sharded queue from tokio-rs#7757 (reverted due to tokio-rs#8056), disabled by
default. Opt in via the unstable `Builder::enable_sharded_blocking_queue` or
the `TOKIO_UNSTABLE_SHARDED_BLOCKING_QUEUE` environment variable.

Refs: tokio-rs#8067

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Darksonn pushed a commit that referenced this pull request Aug 9, 2026
Re-lands the sharded queue from #7757 (reverted due to #8056), disabled by
default. Opt in via the unstable `Builder::enable_sharded_blocking_queue` or
the `TOKIO_UNSTABLE_SHARDED_BLOCKING_QUEUE` environment variable.
ahacop added a commit to ahacop/erwindb that referenced this pull request Sep 28, 2026
[cb skip]

Changes in 1.53.1
-----------------

1.53.1 (July 20th, 2026)
------------------------

Fixed
-----

- signal: restore MSRV by removing `OnceLock::wait` from the Windows handler ([#8300])

Fixed (unstable)
----------------

- time: fix alt timer cancellation and insertion race ([#8252])

Documented
----------

- runtime: remove dead link definition in Runtime::block_on ([#8301])

[#8252]: tokio-rs/tokio#8252
[#8300]: tokio-rs/tokio#8300
[#8301]: tokio-rs/tokio#8301

Changes in 1.53.0
-----------------

1.53.0 (July 17th, 2026)
------------------------

Added
-----

- fs: implement `From<OwnedFd>` and `From<OwnedHandle>` for `File` ([#8266])
- metrics: add task schedule latency metric ([#7986])
- net: add `SocketAddr` methods to Unix sockets ([#8144])

Changed
-------

- io: add `#[inline]` to IO trait impls for in-memory types ([#8242])
- net: implement UCred::pid on FreeBSD ([#8086])
- net: support Nuttx target os ([#8259])
- signal: refactor global variables on Windows ([#8231])
- sync: `mpsc::{Receiver,UnboundedReceiver}` now drops waker on drop, even if there are still senders ([#8095])
- taskdump: support taskdumps on s390x ([#8192])
- time: add `#[track_caller]` to `timeout_at()` ([#8077])
- time: consolidate mutex locks on spurious poll ([#8124])
- time: defer waker clone on spurious poll ([#8107])
- time: move lazy-registration state into `Sleep` ([#8132])
- tracing: remove unnecessary span clone ([#8126])

Fixed
-----

- io: do not treat zero-length reads as EOF in `Chain` ([#8251])
- net: use getpeereid for QNX peer credentials ([#8270])
- runtime: avoid illegal state in `FastRand` ([#8078])
- sync: wake mpsc receiver when a queued `reserve[_many]` returns permits ([#8260])
- taskdump: skip double wake on `Trace::capture`/`Trace::trace_with` ([#8043])
- time: avoid stack overflow in runtime constructor ([#8093])
- time (alt timer): ensure timers stay in the same runtime after `.reset()` ([#8169])

IO uring (unstable)
-------------------

- fs: use io-uring for `fs::try_exists` ([#8080])
- fs: use io-uring for renaming files ([#7800])
- rt: flush io-uring CQE in case of CQE overflow ([#8277])

Documented
----------

- docs: clarify cancel safety wording ([#8181])
- fs: clarify `create_dir_all` succeeds if path exists ([#8149])
- io: add warning about stdout reordering with multiple handles ([#8276])
- net: document pipe `try_read*`/`try_write*` readiness behavior ([#8032])
- runtime: document interaction with fork() ([#8202])
- sync: clarify broadcast lagging semantics ([#8239])
- sync: document memory ordering guarantees for Semaphore ([#8119])
- task: explain why `yield_now` defers its waker ([#8254])
- time: add panic docs to `timeout_at()` ([#8077])
- time: fix reversed poll order in timeout doc ([#8214])

[#7800]: tokio-rs/tokio#7800
[#7986]: tokio-rs/tokio#7986
[#8032]: tokio-rs/tokio#8032
[#8043]: tokio-rs/tokio#8043
[#8077]: tokio-rs/tokio#8077
[#8078]: tokio-rs/tokio#8078
[#8080]: tokio-rs/tokio#8080
[#8086]: tokio-rs/tokio#8086
[#8093]: tokio-rs/tokio#8093
[#8095]: tokio-rs/tokio#8095
[#8107]: tokio-rs/tokio#8107
[#8119]: tokio-rs/tokio#8119
[#8124]: tokio-rs/tokio#8124
[#8126]: tokio-rs/tokio#8126
[#8132]: tokio-rs/tokio#8132
[#8144]: tokio-rs/tokio#8144
[#8149]: tokio-rs/tokio#8149
[#8169]: tokio-rs/tokio#8169
[#8181]: tokio-rs/tokio#8181
[#8192]: tokio-rs/tokio#8192
[#8193]: tokio-rs/tokio#8193
[#8202]: tokio-rs/tokio#8202
[#8214]: tokio-rs/tokio#8214
[#8231]: tokio-rs/tokio#8231
[#8239]: tokio-rs/tokio#8239
[#8242]: tokio-rs/tokio#8242
[#8251]: tokio-rs/tokio#8251
[#8254]: tokio-rs/tokio#8254
[#8259]: tokio-rs/tokio#8259
[#8260]: tokio-rs/tokio#8260
[#8266]: tokio-rs/tokio#8266
[#8270]: tokio-rs/tokio#8270
[#8276]: tokio-rs/tokio#8276
[#8277]: tokio-rs/tokio#8277

Changes in 1.52.4
-----------------

1.52.4 (July 16th, 2026)
------------------------

Fixed
-----

- runtime: don't skip the driver when `before_park` schedules work ([#8222])

Fixed (unstable)
----------------

- taskdump: remove crate disambiguators from output ([#8264])

[#8264]: tokio-rs/tokio#8264
[#8222]: tokio-rs/tokio#8222

Changes in 1.52.3
-----------------

1.52.3 (May 8th, 2026)
----------------------

Fixed
-----

* sync: fix underflow in mpsc channel `len()` ([#8062])
* sync: notify receivers in mpsc `OwnedPermit::release()` method ([#8075])
* sync: require that an `RwLock` has `max_readers != 0` ([#8076])
* sync: return `Empty` from `try_recv()` when mpsc is closed with outstanding permits ([#8074])

[#8062]: tokio-rs/tokio#8062
[#8074]: tokio-rs/tokio#8074
[#8075]: tokio-rs/tokio#8075
[#8076]: tokio-rs/tokio#8076

Changes in 1.52.2
-----------------

1.52.2 (May 4th, 2026)
----------------------

This release reverts the LIFO slot stealing change introduced in 1.51.0 ([#7431]), due to [its performance impact][#8065]. ([#8100])

[#7431]: tokio-rs/tokio#7431
[#8065]: tokio-rs/tokio#8065
[#8100]: tokio-rs/tokio#8100

Changes in 1.52.1
-----------------

1.52.1 (April 16th, 2026)
-------------------------

Fixed
-----

- runtime: revert [#7757] to fix [a regression][#8056] that causes `spawn_blocking` to hang ([#8057])

[#7757]: tokio-rs/tokio#7757
[#8056]: tokio-rs/tokio#8056
[#8057]: tokio-rs/tokio#8057

Changes in 1.52.0
-----------------

1.52.0 (April 14th, 2026)
-------------------------

Added
-----

- io: `AioSource::register_borrowed` for I/O safety support ([#7992])
- net: add `try_io` function to `unix::pipe` sender and receiver types ([#8030])

Added (unstable)
----------------

- runtime: `Builder::enable_eager_driver_handoff` setting enable eager hand off of the I/O and time drivers before polling tasks ([#8010])
- taskdump: add `trace_with()` for customized task dumps ([#8025])
- taskdump: allow `impl FnMut()` in `trace_with` instead of just `fn()` ([#8040])
- fs: support `io_uring` in `AsyncRead` for `File` ([#7907])

Changed
-------

- runtime: improve `spawn_blocking` scalability with sharded queue ([#7757])
- runtime: use `compare_exchange_weak()` in worker queue ([#8028])

Fixed
-----

- runtime: overflow second half of tasks when local queue is filled instead of first half ([#8029])

Documented
----------

- docs: fix typo in `oneshot::Sender::send` docs ([#8026])
- docs: hide #[tokio::main] attribute in the docs of `sync::watch` ([#8035])
- net: add docs on `ConnectionRefused` errors with UDP sockets ([#7870])

[#7757]: tokio-rs/tokio#7757
[#7870]: tokio-rs/tokio#7870
[#7907]: tokio-rs/tokio#7907
[#7992]: tokio-rs/tokio#7992
[#8010]: tokio-rs/tokio#8010
[#8025]: tokio-rs/tokio#8025
[#8026]: tokio-rs/tokio#8026
[#8028]: tokio-rs/tokio#8028
[#8029]: tokio-rs/tokio#8029
[#8030]: tokio-rs/tokio#8030
[#8035]: tokio-rs/tokio#8035
[#8040]: tokio-rs/tokio#8040

Changes in 1.51.4
-----------------

1.51.4 (July 16th, 2026)
------------------------

Fixed
-----

- runtime: don't skip the driver when `before_park` schedules work ([#8222])

[#8222]: tokio-rs/tokio#8222

Changes in 1.51.3
-----------------

1.51.3 (May 8th, 2026)
----------------------

Fixed
-----

* sync: fix underflow in mpsc channel `len()` ([#8062])
* sync: notify receivers in mpsc `OwnedPermit::release()` method ([#8075])
* sync: require that an `RwLock` has `max_readers != 0` ([#8076])
* sync: return `Empty` from `try_recv()` when mpsc is closed with outstanding permits ([#8074])

[#8062]: tokio-rs/tokio#8062
[#8074]: tokio-rs/tokio#8074
[#8075]: tokio-rs/tokio#8075
[#8076]: tokio-rs/tokio#8076

Changes in 1.51.2
-----------------

1.51.2 (May 4th, 2026)
----------------------

This release reverts the LIFO slot stealing change introduced in 1.51.0 ([#7431]), due to [its performance impact][#8065]. ([#8100])

[#7431]: tokio-rs/tokio#7431
[#8065]: tokio-rs/tokio#8065
[#8100]: tokio-rs/tokio#8100

Changes in 1.51.1
-----------------

1.51.1 (April 8th, 2026)
------------------------

Fixed
-----

- sync: fix semaphore reopens after forget ([#8021])
- net: surface errors from `SO_ERROR` on `recv` for UDP sockets on Linux ([#8001])

Fixed (unstable)
----------------

- metrics: fix `worker_local_schedule_count` test ([#8008])
- rt: do not leak fd when cancelling io\_uring open operation ([#7983])

[#7983]: tokio-rs/tokio#7983
[#8001]: tokio-rs/tokio#8001
[#8008]: tokio-rs/tokio#8008
[#8021]: tokio-rs/tokio#8021

Changes in 1.51.0
-----------------

1.51.0 (April 3rd, 2026)
------------------------

Added
-----

- net: implement `get_peer_cred` on Hurd ([#7989])
- runtime: add `tokio::runtime::worker_index()` ([#7921])
- runtime: add runtime name ([#7924])
- runtime: stabilize `LocalRuntime` ([#7557])
- wasm: add wasm32-wasip2 networking support ([#7933])

Changed
-------

- runtime: steal tasks from the LIFO slot ([#7431])

Fixed
-----

- docs: do not show "Available on non-loom only." doc label ([#7977])
- macros: improve overall macro hygiene ([#7997])
- sync: fix `notify_waiters` priority in `Notify` ([#7996])
- sync: fix panic in `Chan::recv_many` when called with non-empty vector on closed channel ([#7991])

[#7431]: tokio-rs/tokio#7431
[#7557]: tokio-rs/tokio#7557
[#7921]: tokio-rs/tokio#7921
[#7924]: tokio-rs/tokio#7924
[#7933]: tokio-rs/tokio#7933
[#7977]: tokio-rs/tokio#7977
[#7989]: tokio-rs/tokio#7989
[#7991]: tokio-rs/tokio#7991
[#7996]: tokio-rs/tokio#7996
[#7997]: tokio-rs/tokio#7997

Changes in 1.50.0
-----------------

1.50.0 (Mar 3rd, 2026)
----------------------

Added
-----

- net: add `TcpStream::set_zero_linger` ([#7837])
- rt: add `is_rt_shutdown_err` ([#7771])

Changed
-------

- io: add optimizer hint that `memchr` returns in-bounds pointer ([#7792])
- io: implement vectored writes for `write_buf` ([#7871])
- runtime: panic when `event_interval` is set to 0 ([#7838])
- runtime: shorten default thread name to fit in Linux limit ([#7880])
- signal: remember the result of `SetConsoleCtrlHandler` ([#7833])
- signal: specialize windows `Registry` ([#7885])

Fixed
-----

- io: always cleanup `AsyncFd` registration list on deregister ([#7773])
- macros: remove (most) local `use` declarations in `tokio::select!` ([#7929])
- net: fix `GET_BUF_SIZE` constant for `target_os = "android"` ([#7889])
- runtime: avoid redundant unpark in current_thread scheduler ([#7834])
- runtime: don't park in `current_thread` if `before_park` defers waker ([#7835])
- io: fix write readiness on ESP32 on short writes ([#7872])
- runtime: wake deferred tasks before entering `block_in_place` ([#7879])
- sync: drop rx waker when oneshot receiver is dropped ([#7886])
- runtime: fix double increment of `num_idle_threads` on shutdown ([#7910], [#7918], [#7922])

Unstable
--------

- fs: check for io-uring opcode support ([#7815])
- runtime: avoid lock acquisition after uring init ([#7850])

Documented
----------

- docs: update outdated unstable features section ([#7839])
- io: clarify the behavior of `AsyncWriteExt::shutdown()` ([#7908])
- io: explain how to flush stdout/stderr ([#7904])
- io: fix incorrect and confusing `AsyncWrite` documentation ([#7875])
- rt: clarify the documentation of `Runtime::spawn` ([#7803])
- rt: fix missing quotation in docs ([#7925])
- runtime: correct the default thread name in docs ([#7896])
- runtime: fix `event_interval` doc ([#7932])
- sync: clarify RwLock fairness documentation ([#7919])
- sync: clarify that `recv` returns `None` once closed and no more messages ([#7920])
- task: clarify when to use `spawn_blocking` vs dedicated threads ([#7923])
- task: doc that task drops before `JoinHandle` completion ([#7825])
- signal: guarantee that listeners never return `None` ([#7869])
- task: fix task module feature flags in docs ([#7891])
- task: fix two typos ([#7913])
- task: improve the docs of `Builder::spawn_local` ([#7828])
- time: add docs about auto-advance and when to use sleep ([#7858])
- util: fix typo in docs ([#7926])

[#7771]: tokio-rs/tokio#7771
[#7773]: tokio-rs/tokio#7773
[#7792]: tokio-rs/tokio#7792
[#7803]: tokio-rs/tokio#7803
[#7815]: tokio-rs/tokio#7815
[#7825]: tokio-rs/tokio#7825
[#7828]: tokio-rs/tokio#7828
[#7833]: tokio-rs/tokio#7833
[#7834]: tokio-rs/tokio#7834
[#7835]: tokio-rs/tokio#7835
[#7837]: tokio-rs/tokio#7837
[#7838]: tokio-rs/tokio#7838
[#7839]: tokio-rs/tokio#7839
[#7850]: tokio-rs/tokio#7850
[#7858]: tokio-rs/tokio#7858
[#7869]: tokio-rs/tokio#7869
[#7871]: tokio-rs/tokio#7871
[#7872]: tokio-rs/tokio#7872
[#7875]: tokio-rs/tokio#7875
[#7879]: tokio-rs/tokio#7879
[#7880]: tokio-rs/tokio#7880
[#7885]: tokio-rs/tokio#7885
[#7886]: tokio-rs/tokio#7886
[#7889]: tokio-rs/tokio#7889
[#7891]: tokio-rs/tokio#7891
[#7896]: tokio-rs/tokio#7896
[#7904]: tokio-rs/tokio#7904
[#7908]: tokio-rs/tokio#7908
[#7910]: tokio-rs/tokio#7910
[#7913]: tokio-rs/tokio#7913
[#7918]: tokio-rs/tokio#7918
[#7919]: tokio-rs/tokio#7919
[#7920]: tokio-rs/tokio#7920
[#7922]: tokio-rs/tokio#7922
[#7923]: tokio-rs/tokio#7923
[#7925]: tokio-rs/tokio#7925
[#7926]: tokio-rs/tokio#7926
[#7929]: tokio-rs/tokio#7929
[#7932]: tokio-rs/tokio#7932

Release notes:
- 1.53.1: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.53.1
- 1.53.0: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.53.0
- 1.52.4: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.52.4
- 1.52.3: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.52.3
- 1.52.2: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.52.2
- 1.52.1: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.52.1
- 1.52.0: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.52.0
- 1.51.4: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.51.4
- 1.51.3: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.51.3
- 1.51.2: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.51.2
- 1.51.1: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.51.1
- 1.51.0: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.51.0
- 1.50.0: https://github.com/tokio-rs/tokio/releases/tag/tokio-1.50.0

---

Transitive Dependencies
-----------------------

- libc (0.2.180 -> 0.2.189)
- mio (1.1.1 -> 1.2.3)
- socket2 (0.6.2 -> 0.6.5)
- syn 3.0.6 (added)
- tokio-macros (2.6.0 -> 2.7.2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-blocking Module: tokio/task/blocking R-loom-blocking Run loom `runtime::spawn_blocking` tests on this PR T-performance Topic: performance and benchmarks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heavy contention on blocking

6 participants