Skip to content

Commit a2f40aa

Browse files
authored
Merge branch 'tokio-rs:master' into master
2 parents 8af7576 + bdd64cc commit a2f40aa

File tree

7 files changed

+95
-5
lines changed

7 files changed

+95
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:
5656

5757
```toml
5858
[dependencies]
59-
tokio = { version = "1.44.2", features = ["full"] }
59+
tokio = { version = "1.45.0", features = ["full"] }
6060
```
6161
Then, on your main.rs:
6262

tokio/CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
# 1.45.0 (May 5th, 2025)
2+
3+
### Added
4+
5+
- metrics: stabilize `worker_total_busy_duration`, `worker_park_count`, and
6+
`worker_unpark_count` ([#6899], [#7276])
7+
- process: add `Command::spawn_with` ([#7249])
8+
9+
### Changed
10+
11+
- io: do not require `Unpin` for some trait impls ([#7204])
12+
- rt: mark `runtime::Handle` as unwind safe ([#7230])
13+
- time: revert internal sharding implementation ([#7226])
14+
15+
### Unstable
16+
17+
- rt: remove alt multi-threaded runtime ([#7275])
18+
19+
[#6899]: https://github.com/tokio-rs/tokio/pull/6899
20+
[#7276]: https://github.com/tokio-rs/tokio/pull/7276
21+
[#7249]: https://github.com/tokio-rs/tokio/pull/7249
22+
[#7204]: https://github.com/tokio-rs/tokio/pull/7204
23+
[#7230]: https://github.com/tokio-rs/tokio/pull/7230
24+
[#7226]: https://github.com/tokio-rs/tokio/pull/7226
25+
[#7275]: https://github.com/tokio-rs/tokio/pull/7275
26+
27+
128
# 1.44.2 (April 5th, 2025)
229

330
This release fixes a soundness issue in the broadcast channel. The channel

tokio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "tokio"
66
# - README.md
77
# - Update CHANGELOG.md.
88
# - Create "v1.x.y" git tag.
9-
version = "1.44.2"
9+
version = "1.45.0"
1010
edition = "2021"
1111
rust-version = "1.70"
1212
authors = ["Tokio Contributors <[email protected]>"]

tokio/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:
5656

5757
```toml
5858
[dependencies]
59-
tokio = { version = "1.44.2", features = ["full"] }
59+
tokio = { version = "1.45.0", features = ["full"] }
6060
```
6161
Then, on your main.rs:
6262

tokio/src/net/tcp/stream.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,16 @@ impl TcpStream {
11121112
/// This function will cause all pending and future I/O on the specified
11131113
/// portions to return immediately with an appropriate value (see the
11141114
/// documentation of `Shutdown`).
1115+
///
1116+
/// Remark: this function transforms `Err(std::io::ErrorKind::NotConnected)` to `Ok(())`.
1117+
/// It does this to abstract away OS specific logic and to prevent a race condition between
1118+
/// this function call and the OS closing this socket because of external events (e.g. TCP reset).
1119+
/// See <https://github.com/tokio-rs/tokio/issues/4665> for more information.
11151120
pub(super) fn shutdown_std(&self, how: Shutdown) -> io::Result<()> {
1116-
self.io.shutdown(how)
1121+
match self.io.shutdown(how) {
1122+
Err(err) if err.kind() == std::io::ErrorKind::NotConnected => Ok(()),
1123+
result => result,
1124+
}
11171125
}
11181126

11191127
/// Gets the value of the `TCP_NODELAY` option on this socket.

tokio/src/runtime/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ impl Builder {
770770
/// # }
771771
/// ```
772772
#[cfg(tokio_unstable)]
773+
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
773774
pub fn on_before_task_poll<F>(&mut self, f: F) -> &mut Self
774775
where
775776
F: Fn(&TaskMeta<'_>) + Send + Sync + 'static,
@@ -813,6 +814,7 @@ impl Builder {
813814
/// # }
814815
/// ```
815816
#[cfg(tokio_unstable)]
817+
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
816818
pub fn on_after_task_poll<F>(&mut self, f: F) -> &mut Self
817819
where
818820
F: Fn(&TaskMeta<'_>) + Send + Sync + 'static,

tokio/tests/tcp_shutdown.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
#![cfg(all(feature = "full", not(target_os = "wasi"), not(miri)))] // Wasi doesn't support bind
33
// No `socket` on miri.
44

5+
use std::time::Duration;
56
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
67
use tokio::net::{TcpListener, TcpStream};
8+
use tokio::sync::oneshot::channel;
79
use tokio_test::assert_ok;
810

911
#[tokio::test]
1012
async fn shutdown() {
1113
let srv = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
1214
let addr = assert_ok!(srv.local_addr());
1315

14-
tokio::spawn(async move {
16+
let handle = tokio::spawn(async move {
1517
let mut stream = assert_ok!(TcpStream::connect(&addr).await);
1618

1719
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
@@ -26,4 +28,55 @@ async fn shutdown() {
2628

2729
let n = assert_ok!(io::copy(&mut rd, &mut wr).await);
2830
assert_eq!(n, 0);
31+
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
32+
handle.await.unwrap()
33+
}
34+
35+
#[tokio::test]
36+
async fn shutdown_after_tcp_reset() {
37+
let srv = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
38+
let addr = assert_ok!(srv.local_addr());
39+
40+
let (connected_tx, connected_rx) = channel();
41+
let (dropped_tx, dropped_rx) = channel();
42+
43+
let handle = tokio::spawn(async move {
44+
let mut stream = assert_ok!(TcpStream::connect(&addr).await);
45+
connected_tx.send(()).unwrap();
46+
47+
dropped_rx.await.unwrap();
48+
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
49+
});
50+
51+
let (stream, _) = assert_ok!(srv.accept().await);
52+
// By setting linger to 0 we will trigger a TCP reset
53+
stream.set_linger(Some(Duration::new(0, 0))).unwrap();
54+
connected_rx.await.unwrap();
55+
56+
drop(stream);
57+
dropped_tx.send(()).unwrap();
58+
59+
handle.await.unwrap();
60+
}
61+
62+
#[tokio::test]
63+
async fn shutdown_multiple_calls() {
64+
let srv = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
65+
let addr = assert_ok!(srv.local_addr());
66+
67+
let (connected_tx, connected_rx) = channel();
68+
69+
let handle = tokio::spawn(async move {
70+
let mut stream = assert_ok!(TcpStream::connect(&addr).await);
71+
connected_tx.send(()).unwrap();
72+
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
73+
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
74+
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
75+
});
76+
77+
let (mut stream, _) = assert_ok!(srv.accept().await);
78+
connected_rx.await.unwrap();
79+
80+
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
81+
handle.await.unwrap();
2982
}

0 commit comments

Comments
 (0)