Commit Graph
2849 Commits
Author SHA1 Message Date
b-naber f84c4d596a io: add StreamReader::into_inner_with_chunk (#4559) 2022-03-23 20:41:09 +01:00
Taiki Endo 121769c762 ci: run reusable_box tests with Miri (#4578) 2022-03-21 23:57:47 +09:00
Jedidiah Buck McCready 0abe825b72 time: clarify platform specific timer resolution (#4474) 2022-03-16 15:49:16 +00:00
Eliza Weisman 61e37c6c8d ci: run doctests for unstable APIs (#4562)
It turns out that the CI job for testing `tokio_unstable` features isn't
actually running doctests for `tokio_unstable`, just lib and integration
tests. This is because RustDoc is responsible for running doctests, and
it needs the unstable cfg passed to it separately from `RUSTFLAGS`.

This means that if the examples for unstable APIs are broken, CI won't
catch this, which is not great!

This commit changes the `test-unstable` CI job to pass `--cfg
tokio_unstable` in `RUSTDOCFLAGS` as well as `RUSTFLAGS`. This way,
doctests for unstable APIs should actually run.

I also fixed a typo in one of the runtime metrics doctests that was
causing a compilation error, which was caught as a result of actually
testing the unstable API docs on CI. :)

Signed-off-by: Eliza Weisman <[email protected]>
2022-03-11 20:13:51 +00:00
Eliza Weisman dee26c92dd chore: fix a bunch of annoying clippy lints (#4558)
## Motivation

Recent Clippy releases have added some new lints that trigger on some
code in Tokio. These aren't a big deal, but seeing them in my editor is
mildly annoying.

## Solution

This branch fixes the following issues flagged by Clippy:

* manual `Option::map` implementation
* use of `.map(...).flatten(...)` that could be replaced with
  `.and_then(...)`
* manual implementation of saturating arithmetic on `Duration`s
* simplify some boolean expressions in assertions (`!res.is_ok()` can be
`res.is_err()`)
* fix redundant field names in initializers
* replace an unnecessary cast to `usize` with an explicitly typed
  integer literal

Signed-off-by: Eliza Weisman <[email protected]>
2022-03-08 12:24:19 -08:00
b-naber 2f944dfa1b sync: add broadcast::Receiver::len (#4542) 2022-03-07 13:47:26 +01:00
weisbrja e8ae65a697 tokio: add support for signals up to SIGRTMAX (#4555)
The POSIX standard not only supports "reliable signals", but also
"real-time signals". This commit adds support for the latter.
2022-03-05 06:33:32 +00:00
Rafael Camargo LeiteandRafael 5b947ca2c7 runtime: include more documentation for thread_pool/worker (#4511)
Co-authored-by: Rafael <[email protected]>
2022-03-02 13:55:15 +01:00
Alisue 014be71cca stream: expose Elapsed error (#4502) 2022-03-02 13:53:21 +01:00
William ba49294bae macros: rename tokio::select!'s internal util module (#4543)
This internal module's identifier can clash with existing identifiers in library users' code and produce confusing error messages.
2022-03-02 13:37:37 +01:00
Alex Saveau fb9a01b362 runtime: use Vec::with_capacity when building runtime (#4553) 2022-03-02 12:41:43 +01:00
Quinn 6f9a586214 sync: unbounded receiver close docs (#4548) 2022-02-27 22:12:29 +01:00
Andy Barron 3dd5a0d3bb signal: add SignalKind Hash/Eq impls and c_int conversion (#4540) 2022-02-26 13:23:28 +01:00
Gus Wynn 413c812ac8 util: switch tokio-util from log to tracing (#4539) 2022-02-26 12:47:04 +01:00
Eliza Weisman ac69d37302 task: fix broken link in AbortHandle RustDoc (#4545)
## Motivation

There's a broken docs link in the docs for `AbortHandle`. Somehow this
managed to slip past CI yesterday when #4530 was merged
(https://github.com/tokio-rs/tokio/runs/5325278596?check_suite_focus=true)
but it's breaking the build now
(https://github.com/tokio-rs/tokio/runs/5337182732?check_suite_focus=true)
which seems really weird to me, but...whatever...

## Solution

This branch fixes the broken link lol.

Signed-off-by: Eliza Weisman <[email protected]>
2022-02-25 19:07:59 +00:00
Cody Casterline 4485921ba7 Improve docs for tokio_unstable. (#4524) 2022-02-25 12:36:37 -05:00
Antonin Amand 70c10bae60 runtime: recover when OS fails to spawn a new thread (#4485) 2022-02-25 12:28:56 +01:00
Eliza Weisman 8e0e56fdf2 task: add AbortHandle type for cancelling tasks in a JoinSet (#4530)
## Motivation

Before we stabilize the `JoinSet` API, we intend to add a method for
individual tasks in the `JoinSet` to be aborted. Because the
`JoinHandle`s for the tasks spawned on a `JoinSet` are owned by the
`JoinSet`, the user can no longer use them to abort tasks on the
`JoinSet`. Therefore, we need another way to cause a remote abort of a
task on a `JoinSet` without holding its `JoinHandle`.

## Solution

This branch adds a new `AbortHandle` type in `tokio::task`, which
represents the owned permission to remotely cancel a task, but _not_ to
await its output. The `AbortHandle` type holds an additional reference
to the task cell.

A crate-private method is added to `JoinHandle` that returns an
`AbortHandle` for the same task, incrementing its ref count.
`AbortHandle` provides a single method, `AbortHandle::abort(self)`, that
remotely cancels the task. Dropping an `AbortHandle` decrements the
task's ref count but does not cancel it. The `AbortHandle` type is
currently marked as unstable.

The spawning methods on `JoinSet` are modified to return an
`AbortHandle` that can be used to cancel the spawned task.

## Future Work

- Currently, the `AbortHandle` type is _only_ available in the public
API through a `JoinSet`. We could also make the
`JoinHandle::abort_handle` method public, to allow users to use the
`AbortHandle` type in other contexts. I didn't do that in this PR,
because I wanted to make the API addition as minimal as possible, but we
could make this method public later.

- Currently, `AbortHandle` is not `Clone`. We could easily make it
`Clone` by incrementing the task's ref count. Since this adds more trait
impls to the API, we may want to be cautious about this, but I see no
obvious reason we would need to remove a `Clone` implementation if one
was added...

- There's been some discussion of adding a `JoinMap` type that allows
aborting tasks by key, and manages a hash map of keys to `AbortHandle`s,
and removes the tasks from the map when they complete. This would make
aborting by key much easier, since the user wouldn't have to worry about
keeping the state of the map of abort handles and the tasks actually
active on the `JoinSet` in sync. After thinking about it a bit, I
thought this is probably best as a `tokio-util` API --- it can currently
be implemented in `tokio-util` with the APIs added in `tokio` in this
PR.

- I noticed while working on this that `JoinSet::join_one` and
`JoinSet::poll_join_one` return a cancelled `JoinError` when a task is
cancelled. I'm not sure if I love this behavior --- it seems like it
would be nicer to just skip cancelled tasks and continue polling. But,
there are currently tests that expect a cancelled `JoinError` to be
returned for each cancelled task, so I didn't want to change it in
_this_ PR. I think this is worth revisiting before stabilizing the API,
though?

Signed-off-by: Eliza Weisman <[email protected]>
2022-02-24 13:08:23 -08:00
Eliza Weisman dfac73d580 macros: update trybuild output for Rust 1.59.0 (#4536)
## Motivation

Rust error messages seem to have changed a bit in 1.59.0

## Solution

Update the `trybuild` stderr output.

This should unbreak the tests on the latest Rust (and fix CI).
2022-02-24 11:52:47 -08:00
Lucio Franco 769fb1547f tokio: Add initial io driver metrics (#4507) 2022-02-24 13:39:37 -05:00
Eliza Weisman 0b97567b49 task: fix missing doc(cfg(...)) attributes for JoinSet (#4531)
## Motivation

The `JoinSet` type is currently missing the `tokio_unstable` and
`feature = "rt"` `doc(cfg(...))` attributes, making it erroneously
appear to be available without the required feature and without unstable
features enabled. This is incorrect.

I believe this is because `doc(cfg(...))` on a re-export doesn't
actually add the required cfgs to the type itself, and the
`cfg_unstable!` is currently only guarding a re-export and module.

## Solution

This PR fixes the missing attributes.
2022-02-23 13:03:41 -08:00
Nikolai Vazquez 3f508d1622 codec: add length_field_type to LengthDelimitedCodec builder (#4508) 2022-02-23 11:46:52 +01:00
Takuya Kajiwara 503ae34cd3 util: fix import path of CancellationToken in example code (#4520) 2022-02-23 11:46:35 +01:00
Alice Ryhl ff8befbc54 ci: fix test not working on wasm (#4527) 2022-02-23 11:46:17 +01:00
Nylonicious 067ddff063 sync: add watch::Sender::send_modify method (#4310) 2022-02-22 21:19:21 +01:00
DevSabbandDevSabb e8f19e771f macros: fix select macro to process 64 branches (#4519)
Co-authored-by: DevSabb <devsabb@local>
2022-02-21 08:41:52 +01:00
Eliza Weisman 43c224ff47 chore: prepare Tokio v1.17.0 release (#4504)
# 1.17.0 (February 16, 2022)

This release updates the minimum supported Rust version (MSRV) to 1.49,
the `mio` dependency to v0.8, and the (optional) `parking_lot`
dependency to v0.12. Additionally, it contains several bug fixes, as
well as internal refactoring and performance improvements.

### Fixed

- time: prevent panicking in `sleep` with large durations ([#4495])
- time: eliminate potential panics in `Instant` arithmetic on platforms
  where `Instant::now` is not monotonic ([#4461])
- io: fix `DuplexStream` not participating in cooperative yielding
  ([#4478])
- rt: fix potential double panic when dropping a `JoinHandle` ([#4430])

### Changed

- update minimum supported Rust version to 1.49 ([#4457])
- update `parking_lot` dependency to v0.12.0 ([#4459])
- update `mio` dependency to v0.8 ([#4449])
- rt: remove an unnecessary lock in the blocking pool ([#4436])
- rt: remove an unnecessary enum in the basic scheduler ([#4462])
- time: use bit manipulation instead of modulo to improve performance
  ([#4480])
- net: use `std::future::Ready` instead of our own `Ready` future
  ([#4271])
- replace deprecated `atomic::spin_loop_hint` with `hint::spin_loop`
  ([#4491])
- fix miri failures in intrusive linked lists ([#4397])

### Documented

- io: add an example for `tokio::process::ChildStdin` ([#4479])

### Unstable

The following changes only apply when building with `--cfg
tokio_unstable`:

- task: fix missing location information in `tracing` spans generated by
  `spawn_local` ([#4483])
- task: add `JoinSet` for managing sets of tasks ([#4335])
- metrics: fix compilation error on MIPS ([#4475])
- metrics: fix compilation error on arm32v7 ([#4453])

[#4495]: https://github.com/tokio-rs/tokio/pull/4495
[#4461]: https://github.com/tokio-rs/tokio/pull/4461
[#4478]: https://github.com/tokio-rs/tokio/pull/4478
[#4430]: https://github.com/tokio-rs/tokio/pull/4430
[#4457]: https://github.com/tokio-rs/tokio/pull/4457
[#4459]: https://github.com/tokio-rs/tokio/pull/4459
[#4449]: https://github.com/tokio-rs/tokio/pull/4449
[#4462]: https://github.com/tokio-rs/tokio/pull/4462
[#4436]: https://github.com/tokio-rs/tokio/pull/4436
[#4480]: https://github.com/tokio-rs/tokio/pull/4480
[#4271]: https://github.com/tokio-rs/tokio/pull/4271
[#4491]: https://github.com/tokio-rs/tokio/pull/4491
[#4397]: https://github.com/tokio-rs/tokio/pull/4397
[#4479]: https://github.com/tokio-rs/tokio/pull/4479
[#4483]: https://github.com/tokio-rs/tokio/pull/4483
[#4335]: https://github.com/tokio-rs/tokio/pull/4335
[#4475]: https://github.com/tokio-rs/tokio/pull/4475
[#4453]: https://github.com/tokio-rs/tokio/pull/4453
tokio-1.17.0
2022-02-16 10:50:22 -08:00
Eliza Weisman 8758965206 task: fix unstable API documentation notes (#4503)
## Motivation

PR #4499 made the `JoinSet` API unstable, but did not add a
documentation note explaining unstable features. In general, since the
docs.rs build includes unstable APIs, it's probably worth including
these notes so that users understand what it means for an API to be
unstable.

## Solution

This branch adds a note on unstable APIs to the `JoinSet` type-level
documentation, similar to the notes for `task::Builder` and the runtime
metrics APIs.

Also, I noticed that there was a broken link to the top-level
documentation on unstable APIs in the docs for `task::Builder`, so I
fixed that as well.
2022-02-15 09:57:06 -08:00
Samuel Tardieu 28b983c4bc time: use bit manipulation instead of modulo (#4480)
time: resolve TODO

## Motivation

Existing `TODO` comment in `src/time/driver/wheel/level.rs`.

## Solution

`level_range()` always return a strictly positive power of 2. If `b` is a
strictly positive power of 2, `a - (a % b)` is equal to `a & !(b - 1)`.
2022-02-15 09:26:07 -08:00
Jonathan Johnson 0826f763e0 time: prevent panicking in sleep() with large durations (#4495) 2022-02-15 10:49:41 +01:00
Carl Lerche 37917b821d rt: make JoinSet unstable (#4499) 2022-02-15 10:37:40 +01:00
b-naber 9a3ce91ef5 util: fix waker update condition in CancellationToken (#4497)
There was a missing exclamation mark in the condition we used to test
whether we need a waker update in `check_for_cancellation`.
2022-02-14 13:18:10 -08:00
Thomas de Zeeuw 8fb15da8f8 Update to Mio v0.8
The major breaking change in Mio v0.8 is TcpSocket type being removed.

Replacing Mio's TcpSocket we switch to the socket2 library which
provides a similar type Socket, as well as SockRef, which provide all
options TcpSocket provided (and more!).

Tokio's TcpSocket type is now backed by Socket2 instead of Mio's
TcpSocket. The main pitfall here is that socket2 isn't non-blocking by
default, which Mio obviously is. As a result we have to do potentially
blocking calls more carefully, specifically we need to handle
would-block-like errors when connecting the TcpSocket ourselves.

One benefit for this change is that adding more socket options to
TcpSocket is now merely a single function call away (in most cases
anyway).
2022-02-13 16:56:18 +01:00
Taiki Endo ac0f894dd9 net: use std::future::ready instead of own Ready future (#4271) 2022-02-13 04:54:45 +09:00
Name1e5s 02141db1e1 replace spin_loop_hint with hint::spin_loop (#4491) 2022-02-12 11:47:04 -08:00
Taiki Endo 62274b0710 chore: update minimal mio requirement to 0.7.11 (#4492) 2022-02-12 10:02:46 +01:00
Dirkjan Ochtman 69f135ed60 util: bump tokio dependency to 1.6 to satisfy minimal versions (#4490) 2022-02-12 10:02:07 +01:00
coral ed187ddfb8 doc: Created a simple example for tokio::process::ChildStdin (#4479) 2022-02-11 19:38:12 -08:00
Toby Lawrence e7a0da60cd chore: prepare tokio-util 0.7.0 (#4486) tokio-util-0.7.0 2022-02-10 12:23:58 -05:00
KestrerandToby Lawrence 9c688ecdc3 util: add lifetime parameter to ReusableBoxFuture (#3762)
Co-authored-by: Toby Lawrence <[email protected]>
2022-02-09 14:29:21 -05:00
Toby Lawrence 52fb93dce9 sync: refactored PollSender<T> to fix a subtly broken Sink<T> implementation (#4214)
Signed-off-by: Toby Lawrence <[email protected]>
2022-02-09 12:09:04 -05:00
Taiki Endo 1be8e9dfb7 miri: make miri accept our intrusive linked lists (#4397) 2022-02-09 11:11:17 +01:00
Eliza Weisman ca51f6a980 task: fix missing #[track_caller] in spawn_local (#4483)
PR #3881 factored out the spawning of local tasks on a `LocalSet` into a
function `spawn_local_inner`, so that the implementation could be shared
with the `task::Builder` API. But, that PR neglected to add a
`#[track_caller]` attribute to `spawn_local_inner`, so the `tracing`
spans for local tasks are all generated with `spawn_local_inner` as
their spawn location, rather than forwarding the actual spawn location
from the calling function.

This causes pretty useless results when using `tokio-console` with code
that spawns a number of local tasks, such as Actix
(https://reddit.com/r/rust/comments/snt5fq/can_tokioconsole_profile_actixrt/)

This commit fixes the issue by adding the missing `#[track_caller]`
attribute.
2022-02-09 10:12:06 +01:00
GongLG fd4d2b0a99 io: make duplex stream cooperative (#4470) (#4478) 2022-02-09 09:59:01 +01:00
Benjamin Saunders cf38ba627a util: remove error case from the infallible DelayQueue::poll_elapsed (#4241) 2022-02-08 21:07:33 -05:00
Sunyeop Lee 0b05ef638d codec: implement Encoder<BytesMut> for BytesCodec (#4465) 2022-02-08 09:11:24 -05:00
Alice Ryhl d6143c9566 io: improve safety comment on FillBuf (#4476) 2022-02-07 10:07:58 +01:00
Name1e5s 5690f0c32e metrics: fix build on mips (#4475) 2022-02-07 10:06:03 +01:00
Oliver Gould fc4deaa1d0 time: eliminate panics from Instant arithmetic (#4461)
`Instant::duration_since`, `Instant::elapsed`, and `Instant::sub` may
panic. This is especially dangerous when `Instant::now` travels back in
time. While this isn't supposed to happen, this behavior is highly
platform-dependent (e.g., rust-lang/rust#86470).

This change modifies the behavior of `tokio::time::Instant` to prevent
this class of panic, as proposed for `std::time::Instant` in
rust-lang/rust#89926.
2022-02-06 16:20:03 +01:00
Carl Lerche bc474f1d81 rt: remove unnecessary enum in basic_scheduler (#4462)
The enum is no longer needed. It was used previously to support multiple
kinds of control messages to the scheduler but that has been refactored
out.
2022-02-03 09:14:22 -08:00