Merge 'tokio-1.21.1' into 'master'

This commit is contained in:
Alice Ryhl
2022-09-13 11:43:54 +02:00
6 changed files with 69 additions and 6 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:
```toml
[dependencies]
tokio = { version = "1.21.0", features = ["full"] }
tokio = { version = "1.21.1", features = ["full"] }
```
Then, on your main.rs:
+10
View File
@@ -1,3 +1,13 @@
# 1.21.1 (September 13, 2022)
### Fixed
- net: fix dependency resolution for socket2 ([#5000])
- task: ignore failure to set TLS in `LocalSet` Drop ([#4976])
[#4976]: https://github.com/tokio-rs/tokio/pull/4976
[#5000]: https://github.com/tokio-rs/tokio/pull/5000
# 1.21.0 (September 2, 2022)
This release is the first release of Tokio to intentionally support WASM. The
+4 -3
View File
@@ -6,7 +6,7 @@ name = "tokio"
# - README.md
# - Update CHANGELOG.md.
# - Create "v1.0.x" git tag.
version = "1.21.0"
version = "1.21.1"
edition = "2018"
rust-version = "1.49"
authors = ["Tokio Contributors <[email protected]>"]
@@ -51,6 +51,7 @@ net = [
"mio/os-poll",
"mio/os-ext",
"mio/net",
"socket2",
"winapi/fileapi",
"winapi/handleapi",
"winapi/namedpipeapi",
@@ -58,7 +59,7 @@ net = [
"winapi/winnt",
"winapi/minwindef",
"winapi/accctrl",
"winapi/aclapi"
"winapi/aclapi",
]
process = [
"bytes",
@@ -118,7 +119,7 @@ num_cpus = { version = "1.8.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }
[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies]
socket2 = { version = "0.4.4", features = [ "all" ] }
socket2 = { version = "0.4.4", optional = true, features = [ "all" ] }
# Currently unstable. The API exposed by these features may be broken at any time.
# Requires `--cfg tokio_unstable` to enable.
+1 -1
View File
@@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:
```toml
[dependencies]
tokio = { version = "1.21.0", features = ["full"] }
tokio = { version = "1.21.1", features = ["full"] }
```
Then, on your main.rs:
+32 -1
View File
@@ -635,6 +635,37 @@ impl LocalSet {
f()
})
}
/// This method is like `with`, but it just calls `f` without setting the thread-local if that
/// fails.
fn with_if_possible<T>(&self, f: impl FnOnce() -> T) -> T {
let mut f = Some(f);
let res = CURRENT.try_with(|ctx| {
struct Reset<'a> {
ctx_ref: &'a RcCell<Context>,
val: Option<Rc<Context>>,
}
impl<'a> Drop for Reset<'a> {
fn drop(&mut self) {
self.ctx_ref.replace(self.val.take());
}
}
let old = ctx.replace(Some(self.context.clone()));
let _reset = Reset {
ctx_ref: ctx,
val: old,
};
(f.take().unwrap())()
});
match res {
Ok(res) => res,
Err(_access_error) => (f.take().unwrap())(),
}
}
}
cfg_unstable! {
@@ -746,7 +777,7 @@ impl Default for LocalSet {
impl Drop for LocalSet {
fn drop(&mut self) {
self.with(|| {
self.with_if_possible(|| {
// Shut down all tasks in the LocalOwnedTasks and close it to
// prevent new tasks from ever being added.
self.context.owned.close_and_shutdown_all();
+21
View File
@@ -311,6 +311,27 @@ fn join_local_future_elsewhere() {
});
}
// Tests for <https://github.com/tokio-rs/tokio/issues/4973>
#[cfg(not(tokio_wasi))] // Wasi doesn't support threads
#[tokio::test(flavor = "multi_thread")]
async fn localset_in_thread_local() {
thread_local! {
static LOCAL_SET: LocalSet = LocalSet::new();
}
// holds runtime thread until end of main fn.
let (_tx, rx) = oneshot::channel::<()>();
let handle = tokio::runtime::Handle::current();
std::thread::spawn(move || {
LOCAL_SET.with(|local_set| {
handle.block_on(local_set.run_until(async move {
let _ = rx.await;
}))
});
});
}
#[test]
fn drop_cancels_tasks() {
use std::rc::Rc;