Skip to content

Commit e1909d0

Browse files
authored
Merge branch 'tokio-rs:master' into fs_read_io_uring
2 parents a90b5c7 + 3bf2e53 commit e1909d0

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

tokio/src/net/tcp/socket.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,17 @@ impl TcpSocket {
419419
///
420420
/// If `SO_LINGER` is not specified, and the socket is closed, the system handles the call in a
421421
/// way that allows the process to continue as quickly as possible.
422+
///
423+
/// This option is deprecated because setting `SO_LINGER` on a socket used with Tokio is always
424+
/// incorrect as it leads to blocking the thread when the socket is closed. For more details,
425+
/// please see:
426+
///
427+
/// > Volumes of communications have been devoted to the intricacies of `SO_LINGER` versus
428+
/// > non-blocking (`O_NONBLOCK`) sockets. From what I can tell, the final word is: don't do
429+
/// > it. Rely on the `shutdown()`-followed-by-`read()`-eof technique instead.
430+
/// >
431+
/// > From [The ultimate `SO_LINGER` page, or: why is my tcp not reliable](https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable)
432+
#[deprecated = "`SO_LINGER` causes the socket to block the thread on drop"]
422433
pub fn set_linger(&self, dur: Option<Duration>) -> io::Result<()> {
423434
self.inner.set_linger(dur)
424435
}

tokio/src/net/tcp/stream.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,9 +1278,20 @@ impl TcpStream {
12781278
/// If `SO_LINGER` is not specified, and the stream is closed, the system handles the call in a
12791279
/// way that allows the process to continue as quickly as possible.
12801280
///
1281+
/// This option is deprecated because setting `SO_LINGER` on a socket used with Tokio is
1282+
/// always incorrect as it leads to blocking the thread when the socket is closed. For more
1283+
/// details, please see:
1284+
///
1285+
/// > Volumes of communications have been devoted to the intricacies of `SO_LINGER` versus
1286+
/// > non-blocking (`O_NONBLOCK`) sockets. From what I can tell, the final word is: don't
1287+
/// > do it. Rely on the `shutdown()`-followed-by-`read()`-eof technique instead.
1288+
/// >
1289+
/// > From [The ultimate `SO_LINGER` page, or: why is my tcp not reliable](https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable)
1290+
///
12811291
/// # Examples
12821292
///
12831293
/// ```no_run
1294+
/// # #![allow(deprecated)]
12841295
/// use tokio::net::TcpStream;
12851296
///
12861297
/// # async fn dox() -> Result<(), Box<dyn std::error::Error>> {
@@ -1290,6 +1301,7 @@ impl TcpStream {
12901301
/// # Ok(())
12911302
/// # }
12921303
/// ```
1304+
#[deprecated = "`SO_LINGER` causes the socket to block the thread on drop"]
12931305
pub fn set_linger(&self, dur: Option<Duration>) -> io::Result<()> {
12941306
socket2::SockRef::from(self).set_linger(dur)
12951307
}

tokio/tests/tcp_connect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ mod linux {
181181
use std::{net, thread};
182182
183183
#[tokio::test]
184+
#[expect(deprecated)] // set_linger is deprecated
184185
fn poll_hup() {
185186
let addr = assert_ok!("127.0.0.1:0".parse());
186187
let mut srv = assert_ok!(TcpListener::bind(&addr));

tokio/tests/tcp_shutdown.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async fn shutdown() {
3333
}
3434

3535
#[tokio::test]
36+
#[expect(deprecated)] // set_linger is deprecated
3637
async fn shutdown_after_tcp_reset() {
3738
let srv = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
3839
let addr = assert_ok!(srv.local_addr());

tokio/tests/tcp_socket.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async fn bind_before_connect() {
6262
}
6363

6464
#[tokio::test]
65+
#[expect(deprecated)] // set_linger is deprecated
6566
async fn basic_linger() {
6667
// Create server
6768
let addr = assert_ok!("127.0.0.1:0".parse());

tokio/tests/tcp_stream.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::time::Duration;
1414

1515
#[tokio::test]
1616
#[cfg_attr(miri, ignore)] // No `socket` on miri.
17+
#[expect(deprecated)] // set_linger is deprecated
1718
async fn set_linger() {
1819
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
1920

0 commit comments

Comments
 (0)