From 97e981e7973dfc7a197839e233a3f2ac7171edc3 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Tue, 13 Sep 2022 08:50:30 +0200 Subject: [PATCH 1/3] net: fix dependency resolution for socket2 (#5000) --- tokio/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index b10b84ce8..f3bbe86cd 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -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. From e4cbc70279f8ee81c7ce7b57edf8a56844da1f39 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Tue, 13 Sep 2022 08:51:04 +0200 Subject: [PATCH 2/3] task: ignore failure to set TLS in LocalSet Drop (#4976) --- tokio/src/task/local.rs | 33 ++++++++++++++++++++++++++++++++- tokio/tests/task_local_set.rs | 21 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index a5bd1bb88..3786cf366 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -633,6 +633,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(&self, f: impl FnOnce() -> T) -> T { + let mut f = Some(f); + + let res = CURRENT.try_with(|ctx| { + struct Reset<'a> { + ctx_ref: &'a Cell>>, + val: Option>, + } + 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! { @@ -744,7 +775,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(); diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs index b6245acf7..e3c0c65f7 100644 --- a/tokio/tests/task_local_set.rs +++ b/tokio/tests/task_local_set.rs @@ -311,6 +311,27 @@ fn join_local_future_elsewhere() { }); } +// Tests for +#[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; From dea1cd49955ab5e9d041e9f1ed0c5f28e18246de Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Tue, 13 Sep 2022 11:20:59 +0200 Subject: [PATCH 3/3] chore: prepare Tokio v1.21.1 (#5003) --- README.md | 2 +- tokio/CHANGELOG.md | 10 ++++++++++ tokio/Cargo.toml | 2 +- tokio/README.md | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 264dde006..07b2e8d61 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/tokio/CHANGELOG.md b/tokio/CHANGELOG.md index fcb4a7406..5ca9e5215 100644 --- a/tokio/CHANGELOG.md +++ b/tokio/CHANGELOG.md @@ -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 diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index f3bbe86cd..2e172ee85 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -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 "] diff --git a/tokio/README.md b/tokio/README.md index 264dde006..07b2e8d61 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -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: