Commit Graph
1953 Commits
Author SHA1 Message Date
Zephyr ShannonandGitHub cbb4abc8ae chore: add audit check (#2595) 2020-07-21 15:32:54 -07:00
Alice RyhlandGitHub 14723f9786 doc: update links in README.md and CONTRIBUTING.md (#2609) 2020-07-21 15:31:26 -07:00
04a2826084 provide a way to drop a runtime in an async context (#2646)
Dropping a runtime normally involves waiting for any outstanding blocking tasks
to complete. When this drop happens in an asynchronous context, we previously
would issue a cryptic panic due to trying to block in an asynchronous context.

This change improves the panic message, and adds a `shutdown_blocking()` function
which can be used to shutdown a runtime without blocking at all, as an out for
cases where this really is necessary.

Co-authored-by: Bryan Donlan <[email protected]>
Co-authored-by: Alice Ryhl <[email protected]>
2020-07-21 15:26:47 -07:00
Mikail BagishovandGitHub 28a93e6044 Update doc comments (#2572)
* Update doc comments

* Remove trailing whitespace
2020-07-20 14:50:59 -07:00
Markus WesterlindandGitHub dd28831e13 io: Forward poll_write_buf on BufReader (#2654)
For some yet unknown reason using the default on a wrapped `Bufreader<TcpStream>`
causes the hyper server to sometimes fail to send the entire body in the
response.

This fixes that problem for us and ensures that hyper has a chance to
use vectored IO (making it a good change regardless of the mentioned
bug)
2020-07-20 14:49:38 -07:00
nicolaiunreinandGitHub 6dcce1901a sync: remove misleading comment (#2666)
We are not returning the old value. I suppose this was once indented and this
is a leftover.
2020-07-20 14:30:28 -07:00
Blas Rodriguez IrizarandGitHub 32f46d7b88 time: improve Entry field comment (#2671)
Applying a suggestion from #2617 to make the sentence more clear.
2020-07-20 14:29:25 -07:00
Alice RyhlandGitHub 356c81c977 dns: document that strings require the DNS feature (#2663) 2020-07-20 14:27:34 -07:00
Alice RyhlandGitHub d685bceb03 sync: "which kind of mutex?" section added to doc (#2658) 2020-07-20 19:15:15 +02:00
Alice RyhlandGitHub b094ee90e2 chore: fix new manual_non_exhaustive clippy lint (#2669)
Our minimum supported Rust version does not allow switching to `#[non_exhaustive]`.
2020-07-20 09:23:19 -07:00
Evan CameronandGitHub 7e4edb8963 io: add little endian variants for AsyncRead/WriteExt (#1915) 2020-07-16 07:50:43 +02:00
fc63fa2606 rt: allow block_on inside block_in_place inside block_on (#2645)
A fast path in block_on_place was failing to call exit() in the case where we
were in a block_on call.

Fixes: #2639

Co-authored-by: Bryan Donlan <[email protected]>
2020-07-14 21:31:13 -07:00
Eliza WeismanandGitHub b9e3d2edde task: add Tracing instrumentation to spawned tasks (#2655)
## Motivation

When debugging asynchronous systems, it can be very valuable to inspect
what tasks are currently active (see #2510). The [`tracing` crate] and
related libraries provide an interface for Rust libraries and
applications to emit and consume structured, contextual, and async-aware
diagnostic information. Because this diagnostic information is
structured and machine-readable, it is a better fit for the
task-tracking use case than textual logging — `tracing` spans can be
consumed to generate metrics ranging from a simple counter of active
tasks to histograms of poll durations, idle durations, and total task
lifetimes. This information is potentially valuable to both Tokio users
*and* to maintainers.

Additionally, `tracing` is maintained by the Tokio project and is
becoming widely adopted by other libraries in the "Tokio stack", such as
[`hyper`], [`h2`], and [`tonic`] and in [other] [parts] of the broader Rust
ecosystem. Therefore, it is suitable for use in Tokio itself.

[`tracing` crate]: https://github.com/tokio-rs/tracing
[`hyper`]: https://github.com/hyperium/hyper/pull/2204
[`h2`]: https://github.com/hyperium/h2/pull/475
[`tonic`]: https://github.com/hyperium/tonic/blob/570c606397e47406ec148fe1763586e87a8f5298/tonic/Cargo.toml#L48
[other]: https://github.com/rust-lang/chalk/pull/525
[parts]: https://github.com/rust-lang/compiler-team/issues/331

## Solution

This PR is an MVP for instrumenting Tokio with `tracing` spans. When the
"tracing" optional dependency is enabled, every spawned future will be
instrumented with a `tracing` span.

The generated spans are at the `TRACE` verbosity level, and have the
target "tokio::task", which may be used by consumers to filter whether
they should be recorded. They include fields for the type name of the
spawned future and for what kind of task the span corresponds to (a
standard `spawn`ed task, a local task spawned by `spawn_local`, or a
`blocking` task spawned by `spawn_blocking`). Because `tracing` has
separate concepts of "opening/closing" and "entering/exiting" a span, we
enter these spans every time the spawned task is polled. This allows
collecting data such as:

 - the total lifetime of the task from `spawn` to `drop`
 - the number of times the task was polled before it completed
 - the duration of each individual time that the span was polled (and
   therefore, aggregated metrics like histograms or averages of poll
   durations)
 - the total time a span was actively being polled, and the total time
   it was alive but **not** being polled
 - the time between when the task was `spawn`ed and the first poll

As an example, here is the output of a version of the `chat` example
instrumented with `tracing`:
![image](https://user-images.githubusercontent.com/2796466/87231927-e50f6900-c36f-11ea-8a90-6da9b93b9601.png)
And, with multiple connections actually sending messages:
![trace_example_1](https://user-images.githubusercontent.com/2796466/87231876-8d70fd80-c36f-11ea-91f1-0ad1a5b3112f.png)


I haven't added any `tracing` spans in the example, only converted the
existing `println!`s to `tracing::info` and `tracing::error` for
consistency. The span durations in the above output are generated by
`tracing-subscriber`. Of course, a Tokio-specific subscriber could
generate even more detailed statistics, but that's follow-up work once
basic tracing support has been added.

Note that the `Instrumented` type from `tracing-futures`, which attaches
a `tracing` span to a future, was reimplemented inside of Tokio to avoid
a dependency on that crate. `tracing-futures` has a feature flag that
enables an optional dependency on Tokio, and I believe that if another
crate in a dependency graph enables that feature while Tokio's `tracing`
support is also enabled, it would create a circular dependency that
Cargo wouldn't be able to handle. Also, it avoids a dependency for a
very small amount of code that is unlikely to ever change.

There is, of course, room for plenty of future work here. This might 
include:

 - instrumenting other parts of `tokio`, such as I/O resources and 
   channels (possibly via waker instrumentation)
 - instrumenting the threadpool so that the state of worker threads
   can be inspected
 - writing `tracing-subscriber` `Layer`s to collect and display
   Tokio-specific data from these traces
 - using `track_caller` (when it's stable) to record _where_ a task 
   was `spawn`ed from

However, this is intended as an MVP to get us started on that path.

Signed-off-by: Eliza Weisman <[email protected]>
2020-07-13 16:46:59 -07:00
Antoine MuratandGitHub a23d2b2274 doc: fix typo from "Rust langague" to "Rust language" (#2656)
* doc: fix typo in addr

* doc: fix typo in stream

* doc: fix typo in stream/collect
2020-07-13 08:48:02 -07:00
Carl LercheandGitHub 98e7831479 net: fix OwnedWriteHalf behavior on drop (#2597)
Previously, dropping the Write handle would issue a `shutdown(Both)`. However,
shutting down the read half is not portable and not the correct action to take.

This changes the behavior of OwnedWriteHalf to only perform a `shutdown(Write)`
on drop.
2020-07-12 19:25:58 -07:00
alborqandGitHub 8411a6945f example: close pending connection on proxy exemple (#2590) 2020-07-12 20:33:20 +02:00
f69e5bfb87 fix: Update the docs of "pause" to state that time will still advance (#2647)
* doc: Update the docs of "pause" to state that time will still advance

This was changed in #2059. This had me extremely confused for some time
as my timeouts fired immediately, without the wrapped future that were
waiting on IO to actually run long enough.

I am not sure about the exact wording here but this had me very confused
for some time. Deprecating "pause" and giving it a more accurate name
may be a good idea as well.

```rust
async fn timeout_advances() {
    time::pause();

    timeout(ms(1), async {
        // Change to 1 and the this future resolve, 2 or
        // more and the timeout resolves
        for _ in 0..2 {
            tokio::task::yield_now().await
        }
    })
    .await
    .unwrap();
}

```

* Update tokio/src/time/clock.rs

Co-authored-by: Alice Ryhl <[email protected]>

Co-authored-by: Alice Ryhl <[email protected]>
2020-07-10 09:11:01 -07:00
Taiki EndoandGitHub 2aa8751261 ci: use latest stable compiler on macOS ci (#2643) 2020-07-05 18:48:47 +02:00
htrefilandGitHub be02d36a86 io: allocate buffer directly on heap (#2634) 2020-07-01 14:57:25 -07:00
cf2c05317c sync: update oneshot::Receiver::close doc link (#2630)
Co-authored-by: Alice Ryhl <[email protected]>
2020-06-25 10:43:22 -07:00
João OliveiraandGitHub f0b2b708a7 test: fix new clippy lint (#2631) 2020-06-25 17:32:16 +02:00
Artem PyanykhandGitHub f75e5a7ef4 docs: BufWriter does not flush on drop (#2487)
Fixes: #2484
2020-06-18 21:42:28 +02:00
Jeb RosenandGitHub 0ab28627e2 docs: remove unneeded doc from AsyncReadExt::read_ext() (#2621)
This paragraph from `std::io::Read::read_ext()` applies to
*implementors* of `Read`. Since `AsyncReadExt` can't and shouldn't be
implemented outside of this crate, this documentation is unnecessary.
2020-06-18 21:36:06 +02:00
Alice RyhlandGitHub a43ec11daf sync: channel doc grammar change (#2624) 2020-06-18 21:22:29 +02:00
Alice RyhlandGitHub 3db22e29d1 sync: documentation for mpsc channels (#2600) 2020-06-17 22:14:09 +02:00
Craig PastroandGitHub e2adf2612d time: add example using interval to the time module (#2623) 2020-06-16 11:25:08 +02:00
s0lst1ceandGitHub 2bc6bc14a8 doc: fix typo on select macro (#2622) 2020-06-15 15:30:50 +02:00
Taiki EndoandGitHub d2f81b506a sync: allow unsized types in Mutex and RwLock (#2615) 2020-06-13 03:32:51 +09:00
Taiki EndoandGitHub 6b6e76080a chore: reduce pin related unsafe code (#2613) 2020-06-12 19:49:39 +09:00
Taiki EndoandGitHub 68b4ca9f55 ci: pin compiler version in miri tests (#2614) 2020-06-12 18:37:06 +09:00
Taiki EndoandGitHub 1769f65d37 io: fix unsound pin projection in read_buf and write_buf (#2612) 2020-06-12 14:28:23 +09:00
Taiki EndoandGitHub 1636910f0a net: impl ToSocketAddrs for &[SocketAddr] (#2604) 2020-06-11 11:06:15 +02:00
johnnydai0andGitHub adaa6849a5 docs: fix the link of contributing guide (#2577) 2020-06-11 10:51:49 +02:00
Alice RyhlandGitHub 0a422593f0 doc: add sleep alias to delay_for (#2589) 2020-06-10 23:30:08 +02:00
Taiki EndoandGitHub d22301967b chore: fix macOS ci on github actions (#2602) 2020-06-11 04:51:24 +09:00
Taiki EndoandGitHub 4010335c84 chore: fix ci failure on master (#2593)
* Fix clippy warnings
* Pin rustc version to 1.43.1 in macOS

Refs: https://github.com/rust-lang/rust/issues/73030
2020-06-07 20:38:02 +09:00
‏‏DaveandGitHub be4577e22f io: fix typo on BufReader (#2569) 2020-06-02 08:49:47 +02:00
xliivandGitHub e70a1b6d64 docs: use intra-links in the docs (#2575) 2020-05-31 18:49:04 +02:00
Mikail BagishovandGitHub 9264b837d8 test: fix all clippy lints in tests (#2573) 2020-05-31 14:49:22 +02:00
Mikail BagishovandGitHub db0d6d75b3 chore: fix clippy errors (#2571) 2020-05-30 14:06:03 -07:00
xliivandGitHub f2f30d4cf6 docs: replace method links with intra-links (#2540) 2020-05-30 20:18:01 +02:00
Geoffry SongandGitHub c624cb8ce3 io: update AsyncBufRead documentation (#2564) 2020-05-29 14:00:13 +02:00
MathspyandGitHub f7574d9023 net: add note about into_split's drop (#2567)
This took me a bit to catch on to because I didn't really think there was any reason to investigate the individual documentation of each half. As someone dealing with TCP streams directly for first time (without previous experience from other languages) this caught me by surprise
2020-05-28 10:11:55 +02:00
Alice RyhlandGitHub 954f2b7304 io: fix panic in read_line (#2541)
Fixes: #2532
2020-05-24 23:26:33 +02:00
Geoff ShannonandGitHub d562e58871 ci: start migrating CI to Github Actions (#2531)
This migrates test_tokio, test_sub_crates, and test_integration to
GitHub Actions, as the first step in the migration from Azure Pipelines.
2020-05-25 01:46:48 +09:00
Jon GjengsetandGitHub 9f63911adc coop: Undo budget decrement on Pending (#2549)
This patch updates the coop logic so that the budget is only decremented
if a future makes progress (that is, if it returns `Ready`). This is
realized by restoring the budget to its former value after
`poll_proceed` _unless_ the caller indicates that it made progress.

The thinking here is that we always want tasks to make progress when we
poll them. With the way things were, if a task polled 128 resources that
could make no progress, and just returned `Pending`, then a 129th
resource that _could_ make progress would not be polled. Worse yet, this
could manifest as a deadlock, if the first 128 resources were all
_waiting_ for the 129th resource, since it would _never_ be polled.

The downside of this change is that `Pending` resources now do not take
up any part of the budget, even though they _do_ take up time on the
executor. If a task is particularly aggressive (or unoptimized), and
polls a large number of resources that cannot make progress whenever it
is polled, then coop will allow it to run potentially much longer before
yielding than it could before. The impact of this should be relatively
contained though, because tasks that behaved in this way in the past
probably ignored `Pending` _anyway_, so whether a resource returned
`Pending` due to coop or due to lack of progress may not make a
difference to it.
2020-05-21 17:07:23 -04:00
Mikail BagishovandGitHub 1e54a35325 io: remove zeroing for AsyncRead implementors (#2525) 2020-05-21 19:42:28 +02:00
Charles HovineandGitHub 4f4f4807c3 fs: implement OpenOptionsExt for OpenOptions (#2515)
Trait OpenOptionsExt is now implemented for fs::OpenOption.

In order to access the underlying std::fs::OpenOptions wrapped in
tokio's OpenOption, an as_inner_mut method was added to OpenOption,
only visible to the parent module.

Fixes: #2366
2020-05-21 17:18:58 +02:00
Dmitri ShkurskiandGitHub 8fda5f1984 fs: add DirBuilder (#2524)
The initial idea was to implement  a thin wrapper  around an internally
held `std::fs::DirBuilder` instance.  This, however, didn't work due to
`std::fs::DirBuilder` not having a Copy/Clone traits implemented, which
are necessary  for constructing an instance to move-capture it  into  a
closure.

Instead,  we mirror `std::fs::DirBuilder` configuration by  storing the
`recursive` and (unix-only) `mode`  parameters locally,  which are then
used to construct an `std::fs::DirBuilder` instance on-the-fly.

This commit also mirrors the (unix-only) DirBuilderExt trait from std.

Fixes: #2369
2020-05-21 12:49:36 +02:00
Alice RyhlandGitHub 7cb5e3460c stream: update StreamExt::merge doc (#2520) 2020-05-21 11:54:52 +02:00