summaryrefslogtreecommitdiffstats
path: root/tokio/tests
AgeCommit message (Collapse)Author
2020-09-08io: move StreamReader and ReaderStream into tokio_util (#2788)Alice Ryhl
Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru> Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-09-08process: make `Child::kill` async (#2823)Ivan Petkov
* This changes the `Child::kill` to be an async method which awaits the child after sending a kill signal. This avoids leaving zombie processes on Unix platforms if the caller forgets to await the child after the kill completes * A `start_kill` method was also added on `Child` which only sends the kill signal to the child process. This allows for kill signals to be sent even outside of async contexts.
2020-09-07sync: rename `Notify::notify()` -> `notify_one()` (#2822)Juan Alvarez
Closes: #2813
2020-09-07process: add Child::{wait,try_wait} (#2796)Ivan Petkov
* add Child::try_wait to mirror the std API * replace Future impl on Child with `.wait()` method to bring our APIs closer to those in std and it allow us to internally fuse the future so that repeated calls to `wait` result in the same value (similar to std) without forcing the caller to fuse the outer future * Also change `Child::id` to return an Option result to avoid allowing the caller to accidentally use the pid on Unix systems after the child has been reaped * Also remove deprecated Child methods
2020-09-05fs: remove File::seek (#2810)Zahari Dichev
Fixes: #1993 Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
2020-09-02time: move throttle to StreamExt (#2752)Blas Rodriguez Irizar
Ref: #2727
2020-09-01sync: watch channel breaking changes (#2806)Blas Rodriguez Irizar
Fixes: #2172
2020-08-28fs: implement FromRawFd & FromRawHandle for File (#2792)Nikolai Vazquez
2020-08-27rt: Refactor `Runtime::block_on` to take `&self` (#2782)Lucio Franco
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-08-26sync: add blocking_recv and blocking_send in mpsc (#2684)xd009642
Fixes: #2629
2020-08-23sync: move CancellationToken to tokio-util (#2721)Carl Lerche
* sync: move CancellationToken to tokio-util The `CancellationToken` utility is only available with the `tokio_unstable` flag. This was done as the API is not final, but it adds friction for users. This patch moves `CancellationToken` to tokio-util where it is generally available. The tokio-util crate does not have any constraints on breaking change releases. * fix clippy * clippy again
2020-08-13io: change AsyncRead to use a ReadBuf (#2758)Sean McArthur
Works towards #2716. Changes the argument to `AsyncRead::poll_read` to take a `ReadBuf` struct that safely manages writes to uninitialized memory.
2020-07-31sync: better Debug for Mutex (#2725)Mikail Bagishov
2020-07-28rt: fix potential leak during runtime shutdown (#2649)Émile Grégoire
JoinHandle of threads created by the pool are now tracked and properly joined at shutdown. If the thread does not return within the timeout, then it's not joined and left to the OS for cleanup. Also, break a cycle between wakers held by the timer and the runtime. Fixes #2641, #2535
2020-07-28add: Add `UdpSocket::{try_send,try_send_to}` methods (#1979)Kevin Leimkuhler
2020-07-28Reset coop budget when blocking in block_on (#2711)Jon Gjengset
Previously, we would fail to reset the coop budget in this case, making it so that `coop::poll_proceed` would perpetually yield `Poll::Pending` in nested executers even when run in `block_in_place`. This is also a further improvement on #2645.
2020-07-28io: rewrite read_to_end and read_to_string (#2560)Alice Ryhl
The new implementation changes the behavior such that set_len is called after poll_read. The motivation of this change is that it makes it much more obvious that a rouge panic won't give the caller access to a vector containing exposed uninitialized memory. The new implementation also makes sure to not zero memory twice. Additionally, it makes the various implementations more consistent with each other regarding the naming of variables, and whether we store how many bytes we have read, or how many were in the container originally. Fixes: #2544
2020-07-28macros: silence unreachable_code warning in select! (#2678)Blas Rodriguez Irizar
Solves #2665 by adding #[allow(unreachable_code)] inside a branch matching arm. Co-authored-by: Alice Ryhl <alice@ryhl.io>
2020-07-26time: fix resetting expired timers causing panics (#2587)Felix Giese
* Add Unit Test demonstrating the issue This test demonstrates a panic that occurs when the user inserts an item with an instant in the past, and then tries to reset the timeout using the returned key * Guard reset_at against removals of expired items Trying to remove an already expired Timer Wheel entry (called by DelayQueue.reset()) causes panics in some cases as described in (#2573) This prevents this panic by removing the item from the expired queue and not the wheel in these cases Fixes: #2473
2020-07-25net: add try_recv/from & try_send/to to UnixDatagram (#1677)jean-airoldie
This allows nonblocking sync send & recv operations on the socket.
2020-07-23net: introduce split on UnixDatagram (#2557)cssivision
2020-07-22io: add `io::duplex()` as bidirectional reader/writer (#2661)Sean McArthur
`duplex` returns a pair of connected `DuplexStream`s. `DuplexStream` is a bidirectional type that can be used to simulate IO, but over an in-process piece of memory.
2020-07-21provide a way to drop a runtime in an async context (#2646)bdonlan
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 <bdonlan@amazon.com> Co-authored-by: Alice Ryhl <alice@ryhl.io>
2020-07-14rt: allow block_on inside block_in_place inside block_on (#2645)bdonlan
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 <bdonlan@amazon.com>
2020-07-12net: fix OwnedWriteHalf behavior on drop (#2597)Carl Lerche
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-06-25test: fix new clippy lint (#2631)João Oliveira
2020-06-12chore: reduce pin related unsafe code (#2613)Taiki Endo
2020-06-07chore: fix ci failure on master (#2593)Taiki Endo
* Fix clippy warnings * Pin rustc version to 1.43.1 in macOS Refs: https://github.com/rust-lang/rust/issues/73030
2020-05-31test: fix all clippy lints in tests (#2573)Mikail Bagishov
2020-05-30chore: fix clippy errors (#2571)Mikail Bagishov
2020-05-24io: fix panic in read_line (#2541)Alice Ryhl
Fixes: #2532
2020-05-21fs: add DirBuilder (#2524)Dmitri Shkurski
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-12sync: use intrusive list strategy for broadcast (#2509)Carl Lerche
Previously, in the broadcast channel, receiver wakers were passed to the sender via an atomic stack with allocated nodes. When a message was sent, the stack was drained. This caused a problem when many receivers pushed a waiter node then dropped. The waiter node remained indefinitely in cases where no values were sent. This patch switches broadcast to use the intrusive linked-list waiter strategy used by `Notify` and `Semaphore.
2020-05-12macros: disambiguate the built-in #[test] attribute in macro expansion (#2503)Jeb Rosen
`tokio::test` and related macros now use the absolute path `::core::prelude::v1::test` to refer to the built-in `test` macro. This absolute path was introduced in rust-lang/rust#62086.
2020-05-07rt: set task budget after block_in_place call (#2502)Carl Lerche
In some cases, when a call to `block_in_place` completes, the runtime is reinstated on the thread. In this case, the task budget must also be set in order to avoid starving other tasks on the worker.
2020-05-06sync: simplify the broadcast channel (#2467)Carl Lerche
Replace an ad hoc read/write lock with RwLock. Use The parking_lot RwLock when possible.
2020-05-03sync: move CancellationToken tests (#2477)Carl Lerche
In preparation of work on `CancellationToken` internals, the tests are moved into `tests/` and are updated to not depend on internals.
2020-04-30task: fix LocalSet having a single shared task budget (#2462)Eliza Weisman
## Motivation Currently, an issue exists where a `LocalSet` has a single cooperative task budget that's shared across all futures spawned on the `LocalSet` _and_ by any future passed to `LocalSet::run_until` or `LocalSet::block_on`. Because these methods will poll the `run_until` future before polling spawned tasks, it is possible for that task to _always_ deterministically starve the entire `LocalSet` so that no local tasks can proceed. When the completion of that future _itself_ depends on other tasks on the `LocalSet`, this will then result in a deadlock, as in issue #2460. A detailed description of why this is the case, taken from [this comment][1]: `LocalSet` wraps each time a local task is run in `budget`: https://github.com/tokio-rs/tokio/blob/947045b9445f15fb9314ba0892efa2251076ae73/tokio/src/task/local.rs#L406 This is identical to what tokio's other schedulers do when running tasks, and in theory should give each task its own budget every time it's polled. _However_, `LocalSet` is different from other schedulers. Unlike the runtime schedulers, a `LocalSet` is itself a future that's run on another scheduler, in `block_on`. `block_on` _also_ sets a budget: https://github.com/tokio-rs/tokio/blob/947045b9445f15fb9314ba0892efa2251076ae73/tokio/src/runtime/basic_scheduler.rs#L131 The docs for `budget` state that: https://github.com/tokio-rs/tokio/blob/947045b9445f15fb9314ba0892efa2251076ae73/tokio/src/coop.rs#L73 This means that inside of a `LocalSet`, the calls to `budget` are no-ops. Instead, each future polled by the `LocalSet` is subtracting from a single global budget. `LocalSet`'s `RunUntil` future polls the provided future before polling any other tasks spawned on the local set: https://github.com/tokio-rs/tokio/blob/947045b9445f15fb9314ba0892efa2251076ae73/tokio/src/task/local.rs#L525-L535 In this case, the provided future is `JoinAll`. Unfortunately, every time a `JoinAll` is polled, it polls _every_ joined future that has not yet completed. When the number of futures in the `JoinAll` is >= 128, this means that the `JoinAll` immediately exhausts the task budget. This would, in theory, be a _good_ thing --- if the `JoinAll` had a huge number of `JoinHandle`s in it and none of them are ready, it would limit the time we spend polling those join handles. However, because the `LocalSet` _actually_ has a single shared task budget, this means polling the `JoinAll` _always_ exhausts the entire budget. There is now no budget remaining to poll any other tasks spawned on the `LocalSet`, and they are never able to complete. [1]: https://github.com/tokio-rs/tokio/issues/2460#issuecomment-621403122 ## Solution This branch solves this issue by resetting the task budget when polling a `LocalSet`. I've added a new function to `coop` for resetting the task budget to `UNCONSTRAINED` for the duration of a closure, and thus allowing the `budget` calls in `LocalSet` to _actually_ create a new budget for each spawned local task. Additionally, I've changed `LocalSet` to _also_ ensure that a separate task budget is applied to any future passed to `block_on`/`run_until`. Additionally, I've added a test reproducing the issue described in #2460. This test fails prior to this change, and passes after it. Fixes #2460 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-04-29mutex: add `OwnedMutexGuard` for `Arc<Mutex<T>>`s (#2455)Eliza Weisman
This PR adds a new `OwnedMutexGuard` type and `lock_owned` and `try_lock_owned` methods for `Arc<Mutex<T>>`. This is pretty much the same as the similar APIs added in #2421. I've also corrected some existing documentation that incorrectly implied that the existing `lock` method cloned an internal `Arc` — I think this may be a holdover from `tokio` 0.1's `Lock` type? Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-04-29time: notify when resetting a Delay to a time in the past (#2290)Thomas Whiteway
If a Delay has been polled, then the task that polled it may be waiting for a notification. If the delay gets reset to a time in the past, then it immediately becomes elapsed, so it should notify the relevant task.
2020-04-28rt: fix default thread number logic (#2457)Carl Lerche
Previously, the function picking the default number of threads for the threaded runtime did not factor in `max_threads`. Instead, it only used the value returned by `num_cpus`. However, if `num_cpus` returns a value greater than `max_threads`, then the function would panic. This patch fixes the function by limiting the default number of threads by `max_threads`. Fixes #2452
2020-04-27sync: fix slow receivers in broadcast (#2448)Kevin Leimkuhler
Broadcast uses a ring buffer to store values sent to the channel. In order to deal with slow receivers, the oldest values are overwritten with new values once the buffer wraps. A receiver should be able to calculate how many values it has missed. Additionally, when the broadcast closes, a final value of `None` is sent to the channel. If the buffer has wrapped, this value overwrites the oldest value. This is an issue mainly in a single capacity broadcast when a value is sent and then the sender is dropped. The original value is immediately overwritten with `None` meaning that receivers assume they have lagged behind. **Solution** A value of `None` is no longer sent to the channel when the final sender has been dropped. This solves the single capacity broadcast case by completely removing the behavior of overwriting values when the channel is closed. Now, when the final sender is dropped a closed bit is set on the next slot that the channel is supposed to send to. In the case of a fast receiver, if it finds a slot where the closed bit is set, it knows the channel is closed without locking the tail. In the case of a slow receiver, it must first find out if it has missed any values. This is similar to before, but must be able to account for channel closure. If the channel is not closed, the oldest value may be located at index `n`. If the channel is closed, the oldest value is located at index `n - 1`. Knowing the index where the oldest value is located, a receiver can calculate how many values it may have missed and starts to catch up. Closes #2425
2020-04-24Add Handle::block_on method (#2437)Dan Burkert
2020-04-23stream: fix panic in Merge and Chain size_hint (#2430)Mikail Bagishov
2020-04-21io: remove unsafe from ReadToString (#2384)Geoffry Song
2020-04-20Be more principled about when blocking is ok (#2410)Jon Gjengset
This enables `block_in_place` to be used in more contexts. Specifically, it allows you to block whenever you are off the tokio runtime (like if you are not using tokio, are in a `spawn_blocking` closure, etc.), and in the threaded scheduler's `block_on`. Blocking in `LocalSet` and the basic scheduler's` block_on` is still disallowed. Fixes #2327. Fixes #2393.
2020-04-20sync: add owned semaphore permit (#2421)Alice Ryhl
2020-04-19net: introduce owned split on TcpStream (#2270)Alice Ryhl
2020-04-16Support nested block_in_place (#2409)Jon Gjengset
2020-04-12task: make LocalSet non-Send (#2398)Alice Ryhl
This does not count as a breaking change as it fixes a regression and a soundness bug.