From f456825151d4f11ded8dd20678fc4dcb8dff8c4b Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 19 Feb 2025 21:51:50 -0600 Subject: [PATCH 01/21] net: warn on creating a tokio socket from a nonblocking one. See #5595. This adds a warning when constructing a tokio socket object from an underlying std socket that is not set to nonblocking mode. This warning is likely to incrementally turn into a hard error in the future. --- tokio/src/net/tcp/listener.rs | 5 +++++ tokio/src/net/tcp/stream.rs | 5 +++++ tokio/src/net/udp.rs | 5 +++++ tokio/src/net/unix/datagram/socket.rs | 5 +++++ tokio/src/net/unix/listener.rs | 5 +++++ tokio/src/net/unix/stream.rs | 5 +++++ tokio/src/util/blocking_check.rs | 15 +++++++++++++++ tokio/src/util/mod.rs | 3 +++ 8 files changed, 48 insertions(+) create mode 100644 tokio/src/util/blocking_check.rs diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index 1545e654128..6820d7b751b 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -9,6 +9,7 @@ use std::fmt; use std::io; use std::net::{self, SocketAddr}; use std::task::{ready, Context, Poll}; +use crate::util::blocking_check::check_socket_for_blocking; cfg_net! { /// A TCP socket server, listening for connections. @@ -208,6 +209,8 @@ impl TcpListener { /// non-blocking mode. Otherwise all I/O operations on the listener /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. + /// + /// Tokio's handling of blocking sockets may change in the future. /// /// [`set_nonblocking`]: std::net::TcpListener::set_nonblocking /// @@ -236,6 +239,8 @@ impl TcpListener { /// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function. #[track_caller] pub fn from_std(listener: net::TcpListener) -> io::Result { + check_socket_for_blocking(&listener)?; + let io = mio::net::TcpListener::from_std(listener); let io = PollEvented::new(io)?; Ok(TcpListener { io }) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 0504bf2e1ea..5306098357d 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -13,6 +13,7 @@ use std::io; use std::net::{Shutdown, SocketAddr}; use std::pin::Pin; use std::task::{ready, Context, Poll}; +use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -173,6 +174,8 @@ impl TcpStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// + /// Tokio's handling of blocking sockets may change in the future. + /// /// [`set_nonblocking`]: std::net::TcpStream::set_nonblocking /// /// # Examples @@ -200,6 +203,8 @@ impl TcpStream { /// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function. #[track_caller] pub fn from_std(stream: std::net::TcpStream) -> io::Result { + check_socket_for_blocking(&stream)?; + let io = mio::net::TcpStream::from_std(stream); let io = PollEvented::new(io)?; Ok(TcpStream { io }) diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index 3e20dd03b2c..d2e68796284 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -5,6 +5,7 @@ use std::fmt; use std::io; use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::task::{ready, Context, Poll}; +use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -192,6 +193,8 @@ impl UdpSocket { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// + /// Tokio's handling of blocking sockets may change in the future. + /// /// [`set_nonblocking`]: std::net::UdpSocket::set_nonblocking /// /// # Panics @@ -220,6 +223,8 @@ impl UdpSocket { /// ``` #[track_caller] pub fn from_std(socket: net::UdpSocket) -> io::Result { + check_socket_for_blocking(&socket)?; + let io = mio::net::UdpSocket::from_std(socket); UdpSocket::new(io) } diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs index e475778ef66..eea033764f5 100644 --- a/tokio/src/net/unix/datagram/socket.rs +++ b/tokio/src/net/unix/datagram/socket.rs @@ -8,6 +8,7 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use std::os::unix::net; use std::path::Path; use std::task::{ready, Context, Poll}; +use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -449,6 +450,8 @@ impl UnixDatagram { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// + /// Tokio's handling of blocking sockets may change in the future. + /// /// [`set_nonblocking`]: std::os::unix::net::UnixDatagram::set_nonblocking /// /// # Panics @@ -484,6 +487,8 @@ impl UnixDatagram { /// ``` #[track_caller] pub fn from_std(datagram: net::UnixDatagram) -> io::Result { + check_socket_for_blocking(&datagram)?; + let socket = mio::net::UnixDatagram::from_std(datagram); let io = PollEvented::new(socket)?; Ok(UnixDatagram { io }) diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 9977020a283..63ed6e3bd7b 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -13,6 +13,7 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use std::os::unix::net::{self, SocketAddr as StdSocketAddr}; use std::path::Path; use std::task::{ready, Context, Poll}; +use crate::util::blocking_check::check_socket_for_blocking; cfg_net_unix! { /// A Unix socket which can accept connections from other Unix sockets. @@ -106,6 +107,8 @@ impl UnixListener { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// + /// Tokio's handling of blocking sockets may change in the future. + /// /// [`set_nonblocking`]: std::os::unix::net::UnixListener::set_nonblocking /// /// # Examples @@ -133,6 +136,8 @@ impl UnixListener { /// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function. #[track_caller] pub fn from_std(listener: net::UnixListener) -> io::Result { + check_socket_for_blocking(&listener)?; + let listener = mio::net::UnixListener::from_std(listener); let io = PollEvented::new(listener)?; Ok(UnixListener { io }) diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 16dc03f9a30..c324e27c0ef 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -19,6 +19,7 @@ use std::os::unix::net::{self, SocketAddr as StdSocketAddr}; use std::path::Path; use std::pin::Pin; use std::task::{Context, Poll}; +use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -791,6 +792,8 @@ impl UnixStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// + /// Tokio's handling of blocking sockets may change in the future. + /// /// [`set_nonblocking`]: std::os::unix::net::UnixStream::set_nonblocking /// /// # Examples @@ -818,6 +821,8 @@ impl UnixStream { /// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function. #[track_caller] pub fn from_std(stream: net::UnixStream) -> io::Result { + check_socket_for_blocking(&stream)?; + let stream = mio::net::UnixStream::from_std(stream); let io = PollEvented::new(stream)?; diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs new file mode 100644 index 00000000000..e7802d120e9 --- /dev/null +++ b/tokio/src/util/blocking_check.rs @@ -0,0 +1,15 @@ +use std::os::fd::AsFd; + +#[allow(unused_variables)] +pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { + #[cfg(debug_assertions)] + { + let sock = socket2::SockRef::from(s); + + if !sock.nonblocking()? { + eprintln!("Warning: binding a nonblocking socket, this may be a bug!"); + } + } + + Ok(()) +} diff --git a/tokio/src/util/mod.rs b/tokio/src/util/mod.rs index a93bfe8304f..0b54ba1e846 100644 --- a/tokio/src/util/mod.rs +++ b/tokio/src/util/mod.rs @@ -10,6 +10,9 @@ pub(crate) mod metric_atomics; #[cfg(any(feature = "rt", feature = "signal", feature = "process"))] pub(crate) mod once_cell; +#[cfg(feature = "net")] +pub(crate) mod blocking_check; + #[cfg(any( // io driver uses `WakeList` directly feature = "net", From 857742cab793499b6d6ac04e2b301028b53fbcdd Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 19 Feb 2025 22:00:18 -0600 Subject: [PATCH 02/21] fmt --- tokio/src/net/tcp/listener.rs | 6 +++--- tokio/src/net/tcp/stream.rs | 4 ++-- tokio/src/net/udp.rs | 6 +++--- tokio/src/net/unix/datagram/socket.rs | 4 ++-- tokio/src/net/unix/listener.rs | 4 ++-- tokio/src/net/unix/stream.rs | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index 6820d7b751b..c0766d005e4 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -5,11 +5,11 @@ cfg_not_wasi! { use crate::net::{to_socket_addrs, ToSocketAddrs}; } +use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::{self, SocketAddr}; use std::task::{ready, Context, Poll}; -use crate::util::blocking_check::check_socket_for_blocking; cfg_net! { /// A TCP socket server, listening for connections. @@ -209,7 +209,7 @@ impl TcpListener { /// non-blocking mode. Otherwise all I/O operations on the listener /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. - /// + /// /// Tokio's handling of blocking sockets may change in the future. /// /// [`set_nonblocking`]: std::net::TcpListener::set_nonblocking @@ -240,7 +240,7 @@ impl TcpListener { #[track_caller] pub fn from_std(listener: net::TcpListener) -> io::Result { check_socket_for_blocking(&listener)?; - + let io = mio::net::TcpListener::from_std(listener); let io = PollEvented::new(io)?; Ok(TcpListener { io }) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 5306098357d..35781970f8d 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -8,12 +8,12 @@ use crate::io::{AsyncRead, AsyncWrite, Interest, PollEvented, ReadBuf, Ready}; use crate::net::tcp::split::{split, ReadHalf, WriteHalf}; use crate::net::tcp::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; +use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::{Shutdown, SocketAddr}; use std::pin::Pin; use std::task::{ready, Context, Poll}; -use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -204,7 +204,7 @@ impl TcpStream { #[track_caller] pub fn from_std(stream: std::net::TcpStream) -> io::Result { check_socket_for_blocking(&stream)?; - + let io = mio::net::TcpStream::from_std(stream); let io = PollEvented::new(io)?; Ok(TcpStream { io }) diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index d2e68796284..4d3d8740e0d 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -1,11 +1,11 @@ use crate::io::{Interest, PollEvented, ReadBuf, Ready}; use crate::net::{to_socket_addrs, ToSocketAddrs}; +use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::task::{ready, Context, Poll}; -use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -194,7 +194,7 @@ impl UdpSocket { /// Non-blocking mode can be set using [`set_nonblocking`]. /// /// Tokio's handling of blocking sockets may change in the future. - /// + /// /// [`set_nonblocking`]: std::net::UdpSocket::set_nonblocking /// /// # Panics @@ -224,7 +224,7 @@ impl UdpSocket { #[track_caller] pub fn from_std(socket: net::UdpSocket) -> io::Result { check_socket_for_blocking(&socket)?; - + let io = mio::net::UdpSocket::from_std(socket); UdpSocket::new(io) } diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs index eea033764f5..be986d1c8db 100644 --- a/tokio/src/net/unix/datagram/socket.rs +++ b/tokio/src/net/unix/datagram/socket.rs @@ -1,6 +1,7 @@ use crate::io::{Interest, PollEvented, ReadBuf, Ready}; use crate::net::unix::SocketAddr; +use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::Shutdown; @@ -8,7 +9,6 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use std::os::unix::net; use std::path::Path; use std::task::{ready, Context, Poll}; -use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -451,7 +451,7 @@ impl UnixDatagram { /// Non-blocking mode can be set using [`set_nonblocking`]. /// /// Tokio's handling of blocking sockets may change in the future. - /// + /// /// [`set_nonblocking`]: std::os::unix::net::UnixDatagram::set_nonblocking /// /// # Panics diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 63ed6e3bd7b..4535328f310 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -1,6 +1,7 @@ use crate::io::{Interest, PollEvented}; use crate::net::unix::{SocketAddr, UnixStream}; +use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; #[cfg(target_os = "android")] @@ -13,7 +14,6 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use std::os::unix::net::{self, SocketAddr as StdSocketAddr}; use std::path::Path; use std::task::{ready, Context, Poll}; -use crate::util::blocking_check::check_socket_for_blocking; cfg_net_unix! { /// A Unix socket which can accept connections from other Unix sockets. @@ -137,7 +137,7 @@ impl UnixListener { #[track_caller] pub fn from_std(listener: net::UnixListener) -> io::Result { check_socket_for_blocking(&listener)?; - + let listener = mio::net::UnixListener::from_std(listener); let io = PollEvented::new(listener)?; Ok(UnixListener { io }) diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index c324e27c0ef..97acf417cb8 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -4,6 +4,7 @@ use crate::net::unix::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; use crate::net::unix::ucred::{self, UCred}; use crate::net::unix::SocketAddr; +use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::future::poll_fn; use std::io::{self, Read, Write}; @@ -19,7 +20,6 @@ use std::os::unix::net::{self, SocketAddr as StdSocketAddr}; use std::path::Path; use std::pin::Pin; use std::task::{Context, Poll}; -use crate::util::blocking_check::check_socket_for_blocking; cfg_io_util! { use bytes::BufMut; @@ -822,7 +822,7 @@ impl UnixStream { #[track_caller] pub fn from_std(stream: net::UnixStream) -> io::Result { check_socket_for_blocking(&stream)?; - + let stream = mio::net::UnixStream::from_std(stream); let io = PollEvented::new(stream)?; From 782d37f1d5753b87ee72ae7e141b67de47e913f1 Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 19 Feb 2025 22:05:34 -0600 Subject: [PATCH 03/21] that operating system is a decades-old mistake --- tokio/src/util/blocking_check.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs index e7802d120e9..4a8ae091746 100644 --- a/tokio/src/util/blocking_check.rs +++ b/tokio/src/util/blocking_check.rs @@ -1,5 +1,9 @@ +#[cfg(unix)] use std::os::fd::AsFd; +#[cfg(windows)] +use std::os::windows::io::AsHandle; +#[cfg(unix)] #[allow(unused_variables)] pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { #[cfg(debug_assertions)] @@ -13,3 +17,18 @@ pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> Ok(()) } + +#[cfg(windows)] +#[allow(unused_variables)] +pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { + #[cfg(debug_assertions)] + { + let sock = socket2::SockRef::from(s); + + if !sock.nonblocking()? { + eprintln!("Warning: binding a nonblocking socket, this may be a bug!"); + } + } + + Ok(()) +} From 680f16cf5a8dbb7856b2f942293f2e61b27843d6 Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 19 Feb 2025 22:47:51 -0600 Subject: [PATCH 04/21] docs.rs doesnt have windows so im guessing --- tokio/src/util/blocking_check.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs index 4a8ae091746..82990ed87e1 100644 --- a/tokio/src/util/blocking_check.rs +++ b/tokio/src/util/blocking_check.rs @@ -1,7 +1,7 @@ #[cfg(unix)] use std::os::fd::AsFd; #[cfg(windows)] -use std::os::windows::io::AsHandle; +use std::os::windows::io::AsSocket; #[cfg(unix)] #[allow(unused_variables)] @@ -20,7 +20,7 @@ pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> #[cfg(windows)] #[allow(unused_variables)] -pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { +pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { #[cfg(debug_assertions)] { let sock = socket2::SockRef::from(s); From f4a6df756a42a869080140ecc8136d5930da5044 Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 19 Feb 2025 22:50:11 -0600 Subject: [PATCH 05/21] wat --- tokio/src/util/blocking_check.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs index 82990ed87e1..c018de21dff 100644 --- a/tokio/src/util/blocking_check.rs +++ b/tokio/src/util/blocking_check.rs @@ -21,14 +21,6 @@ pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> #[cfg(windows)] #[allow(unused_variables)] pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { - #[cfg(debug_assertions)] - { - let sock = socket2::SockRef::from(s); - - if !sock.nonblocking()? { - eprintln!("Warning: binding a nonblocking socket, this may be a bug!"); - } - } - + // we cannot retrieve the nonblocking status on windows Ok(()) } From 9826dac2973ef6c895e9b83f93e3a4e1e074e830 Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 19 Feb 2025 22:54:38 -0600 Subject: [PATCH 06/21] sadness --- tokio/src/util/blocking_check.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs index c018de21dff..ffd7ef9d991 100644 --- a/tokio/src/util/blocking_check.rs +++ b/tokio/src/util/blocking_check.rs @@ -1,7 +1,5 @@ #[cfg(unix)] use std::os::fd::AsFd; -#[cfg(windows)] -use std::os::windows::io::AsSocket; #[cfg(unix)] #[allow(unused_variables)] @@ -18,9 +16,10 @@ pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> Ok(()) } -#[cfg(windows)] +#[cfg(not(unix))] #[allow(unused_variables)] -pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { +pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { // we cannot retrieve the nonblocking status on windows + // and i dont know how to support wasi yet Ok(()) } From c958685c61d70cea4a99becdf25723f333b190bd Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 19 Feb 2025 22:59:03 -0600 Subject: [PATCH 07/21] lol what was i doing --- tokio/src/util/blocking_check.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs index ffd7ef9d991..e990bbd01d2 100644 --- a/tokio/src/util/blocking_check.rs +++ b/tokio/src/util/blocking_check.rs @@ -9,7 +9,7 @@ pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> let sock = socket2::SockRef::from(s); if !sock.nonblocking()? { - eprintln!("Warning: binding a nonblocking socket, this may be a bug!"); + eprintln!("Warning: registering a blocking socket, this may be a bug!"); } } From 31f24d84e422cc67e20f000bdd0c52b972978208 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 10:37:26 -0600 Subject: [PATCH 08/21] address feedback --- Cargo.toml | 1 + tokio/src/net/tcp/listener.rs | 4 ++-- tokio/src/net/tcp/stream.rs | 4 ++-- tokio/src/net/udp.rs | 4 ++-- tokio/src/net/unix/datagram/socket.rs | 4 ++-- tokio/src/net/unix/listener.rs | 4 ++-- tokio/src/net/unix/stream.rs | 4 ++-- tokio/src/util/blocking_check.rs | 12 ++++++++---- tokio/src/util/mod.rs | 8 +++++--- 9 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c215946f421..618b310e32c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(fuzzing)', 'cfg(loom)', 'cfg(mio_unsupported_force_poll_poll)', + 'cfg(tokio_allow_from_blocking_fd)', 'cfg(tokio_internal_mt_counters)', 'cfg(tokio_no_parking_lot)', 'cfg(tokio_no_tuning_tests)', diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index c0766d005e4..afc0f58e87b 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -1,11 +1,11 @@ use crate::io::{Interest, PollEvented}; use crate::net::tcp::TcpStream; +use crate::util::check_socket_for_blocking; cfg_not_wasi! { use crate::net::{to_socket_addrs, ToSocketAddrs}; } -use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::{self, SocketAddr}; @@ -210,7 +210,7 @@ impl TcpListener { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Tokio's handling of blocking sockets may change in the future. + /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::net::TcpListener::set_nonblocking /// diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 35781970f8d..1b4e480f00a 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -7,8 +7,8 @@ cfg_not_wasi! { use crate::io::{AsyncRead, AsyncWrite, Interest, PollEvented, ReadBuf, Ready}; use crate::net::tcp::split::{split, ReadHalf, WriteHalf}; use crate::net::tcp::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; +use crate::util::check_socket_for_blocking; -use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::{Shutdown, SocketAddr}; @@ -174,7 +174,7 @@ impl TcpStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Tokio's handling of blocking sockets may change in the future. + /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::net::TcpStream::set_nonblocking /// diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index 4d3d8740e0d..c6fba171bc0 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -1,7 +1,7 @@ use crate::io::{Interest, PollEvented, ReadBuf, Ready}; use crate::net::{to_socket_addrs, ToSocketAddrs}; +use crate::util::check_socket_for_blocking; -use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr}; @@ -193,7 +193,7 @@ impl UdpSocket { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Tokio's handling of blocking sockets may change in the future. + /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::net::UdpSocket::set_nonblocking /// diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs index be986d1c8db..216ee2cb1f7 100644 --- a/tokio/src/net/unix/datagram/socket.rs +++ b/tokio/src/net/unix/datagram/socket.rs @@ -1,7 +1,7 @@ use crate::io::{Interest, PollEvented, ReadBuf, Ready}; use crate::net::unix::SocketAddr; +use crate::util::check_socket_for_blocking; -use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; use std::net::Shutdown; @@ -450,7 +450,7 @@ impl UnixDatagram { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Tokio's handling of blocking sockets may change in the future. + /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixDatagram::set_nonblocking /// diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 4535328f310..e166d95290e 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -1,7 +1,7 @@ use crate::io::{Interest, PollEvented}; use crate::net::unix::{SocketAddr, UnixStream}; +use crate::util::check_socket_for_blocking; -use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::io; #[cfg(target_os = "android")] @@ -107,7 +107,7 @@ impl UnixListener { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Tokio's handling of blocking sockets may change in the future. + /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixListener::set_nonblocking /// diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 97acf417cb8..d5e82d1deac 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -3,8 +3,8 @@ use crate::net::unix::split::{split, ReadHalf, WriteHalf}; use crate::net::unix::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; use crate::net::unix::ucred::{self, UCred}; use crate::net::unix::SocketAddr; +use crate::util::check_socket_for_blocking; -use crate::util::blocking_check::check_socket_for_blocking; use std::fmt; use std::future::poll_fn; use std::io::{self, Read, Write}; @@ -792,7 +792,7 @@ impl UnixStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Tokio's handling of blocking sockets may change in the future. + /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixStream::set_nonblocking /// diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs index e990bbd01d2..c45cbbdfd65 100644 --- a/tokio/src/util/blocking_check.rs +++ b/tokio/src/util/blocking_check.rs @@ -3,14 +3,18 @@ use std::os::fd::AsFd; #[cfg(unix)] #[allow(unused_variables)] +#[track_caller] pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> { - #[cfg(debug_assertions)] + #[cfg(not(tokio_allow_from_blocking_fd))] { let sock = socket2::SockRef::from(s); - if !sock.nonblocking()? { - eprintln!("Warning: registering a blocking socket, this may be a bug!"); - } + debug_assert!( + sock.nonblocking()?, + "Registering a blocking socket with the tokio runtime is unsupported. \ + If you wish to do anyways, please add `--cfg tokio_allow_from_blocking_fd` to your \ + RUSTFLAGS. See 7172 for more details." + ); } Ok(()) diff --git a/tokio/src/util/mod.rs b/tokio/src/util/mod.rs index 0b54ba1e846..4b50f73b5fa 100644 --- a/tokio/src/util/mod.rs +++ b/tokio/src/util/mod.rs @@ -10,9 +10,6 @@ pub(crate) mod metric_atomics; #[cfg(any(feature = "rt", feature = "signal", feature = "process"))] pub(crate) mod once_cell; -#[cfg(feature = "net")] -pub(crate) mod blocking_check; - #[cfg(any( // io driver uses `WakeList` directly feature = "net", @@ -57,6 +54,11 @@ cfg_rt! { #[cfg(any(feature = "rt", feature = "macros", feature = "time"))] pub(crate) mod rand; +cfg_net! { + mod blocking_check; + pub(crate) use blocking_check::check_socket_for_blocking; +} + cfg_rt! { mod idle_notified_set; pub(crate) use idle_notified_set::IdleNotifiedSet; From 0e396e4379bf31a6e0b3d6d76a0d25e9e7d690b1 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 10:54:24 -0600 Subject: [PATCH 09/21] ugh spelling --- tokio/src/net/tcp/listener.rs | 2 +- tokio/src/net/tcp/stream.rs | 2 +- tokio/src/net/udp.rs | 2 +- tokio/src/net/unix/datagram/socket.rs | 2 +- tokio/src/net/unix/listener.rs | 2 +- tokio/src/net/unix/stream.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index afc0f58e87b..093b544881e 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -210,7 +210,7 @@ impl TcpListener { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::net::TcpListener::set_nonblocking /// diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 1b4e480f00a..507476b016a 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -174,7 +174,7 @@ impl TcpStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::net::TcpStream::set_nonblocking /// diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index c6fba171bc0..349ff16ceeb 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -193,7 +193,7 @@ impl UdpSocket { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::net::UdpSocket::set_nonblocking /// diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs index 216ee2cb1f7..d68a4ba1d4d 100644 --- a/tokio/src/net/unix/datagram/socket.rs +++ b/tokio/src/net/unix/datagram/socket.rs @@ -450,7 +450,7 @@ impl UnixDatagram { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixDatagram::set_nonblocking /// diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index e166d95290e..76534562a26 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -107,7 +107,7 @@ impl UnixListener { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixListener::set_nonblocking /// diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index d5e82d1deac..8e5ceb01e13 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -792,7 +792,7 @@ impl UnixStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always errornous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixStream::set_nonblocking /// From bdbf1c7cbc9c0d626420cc1198d844e860c624f4 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 11:00:18 -0600 Subject: [PATCH 10/21] oh right --- tokio/src/util/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tokio/src/util/mod.rs b/tokio/src/util/mod.rs index 4b50f73b5fa..849cc3db05b 100644 --- a/tokio/src/util/mod.rs +++ b/tokio/src/util/mod.rs @@ -5,6 +5,11 @@ cfg_io_driver! { #[cfg(feature = "rt")] pub(crate) mod atomic_cell; +#[cfg(feature = "net")] +mod blocking_check; +#[cfg(feature = "net")] +pub(crate) use blocking_check::check_socket_for_blocking; + pub(crate) mod metric_atomics; #[cfg(any(feature = "rt", feature = "signal", feature = "process"))] @@ -54,11 +59,6 @@ cfg_rt! { #[cfg(any(feature = "rt", feature = "macros", feature = "time"))] pub(crate) mod rand; -cfg_net! { - mod blocking_check; - pub(crate) use blocking_check::check_socket_for_blocking; -} - cfg_rt! { mod idle_notified_set; pub(crate) use idle_notified_set::IdleNotifiedSet; From 0ded9753e8bac32020774715a1e2eac5909ed23e Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 11:07:44 -0600 Subject: [PATCH 11/21] fix bad test --- tokio/tests/io_driver.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tokio/tests/io_driver.rs b/tokio/tests/io_driver.rs index 9f8915fb130..ddb81c64198 100644 --- a/tokio/tests/io_driver.rs +++ b/tokio/tests/io_driver.rs @@ -96,7 +96,10 @@ fn panics_when_io_disabled() { let rt = runtime::Builder::new_current_thread().build().unwrap(); rt.block_on(async { - let _ = - tokio::net::TcpListener::from_std(std::net::TcpListener::bind("127.0.0.1:0").unwrap()); + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + + listener.set_nonblocking(true).unwrap(); + + let _ = tokio::net::TcpListener::from_std(listener); }); } From 277a6f7cbc48ff0e6d25c9342e34abef8b394756 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 11:18:24 -0600 Subject: [PATCH 12/21] fix more tests --- tokio/tests/io_driver_drop.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tokio/tests/io_driver_drop.rs b/tokio/tests/io_driver_drop.rs index 0bbd379a95b..e01679b6eba 100644 --- a/tokio/tests/io_driver_drop.rs +++ b/tokio/tests/io_driver_drop.rs @@ -13,6 +13,9 @@ fn tcp_doesnt_block() { let listener = { let _enter = rt.enter(); let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + + listener.set_nonblocking(true).unwrap(); + TcpListener::from_std(listener).unwrap() }; @@ -33,6 +36,9 @@ fn drop_wakes() { let listener = { let _enter = rt.enter(); let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + + listener.set_nonblocking(true).unwrap(); + TcpListener::from_std(listener).unwrap() }; From 3fe9fdd6ac0cbc0a75beb28093766f91892c6742 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 11:23:41 -0600 Subject: [PATCH 13/21] moar test fixes --- tokio/tests/no_rt.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tokio/tests/no_rt.rs b/tokio/tests/no_rt.rs index 0730090857c..6949db04f4a 100644 --- a/tokio/tests/no_rt.rs +++ b/tokio/tests/no_rt.rs @@ -39,5 +39,7 @@ async fn timeout_value() { )] #[cfg_attr(miri, ignore)] // No `socket` in miri. fn io_panics_when_no_tokio_context() { - let _ = tokio::net::TcpListener::from_std(std::net::TcpListener::bind("127.0.0.1:0").unwrap()); + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + + let _ = tokio::net::TcpListener::from_std(listener); } From cca424b98e9d9331a871e791f24c0b01625f2d94 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 11:43:39 -0600 Subject: [PATCH 14/21] sadness --- tokio/src/util/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tokio/src/util/mod.rs b/tokio/src/util/mod.rs index 849cc3db05b..e585c665cd6 100644 --- a/tokio/src/util/mod.rs +++ b/tokio/src/util/mod.rs @@ -8,6 +8,7 @@ pub(crate) mod atomic_cell; #[cfg(feature = "net")] mod blocking_check; #[cfg(feature = "net")] +#[allow(unused_imports)] pub(crate) use blocking_check::check_socket_for_blocking; pub(crate) mod metric_atomics; From e1f4742a8125e998644202fa70e26a9daf9e4f53 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 21:10:03 -0600 Subject: [PATCH 15/21] lol --- tokio/tests/no_rt.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tokio/tests/no_rt.rs b/tokio/tests/no_rt.rs index 6949db04f4a..0b6ee037b05 100644 --- a/tokio/tests/no_rt.rs +++ b/tokio/tests/no_rt.rs @@ -41,5 +41,7 @@ async fn timeout_value() { fn io_panics_when_no_tokio_context() { let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + listener.set_nonblocking(true).unwrap(); + let _ = tokio::net::TcpListener::from_std(listener); } From f6bb91128ca5d588537dfc6b1e821b2951586076 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 21:30:15 -0600 Subject: [PATCH 16/21] ugh --- tokio/tests/tcp_peek.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index e633badb699..05dafb2a77e 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -13,6 +13,9 @@ use std::{io::Write, net}; #[tokio::test] async fn peek() { let listener = net::TcpListener::bind("127.0.0.1:0").unwrap(); + + listener.set_nonblocking(true).unwrap(); + let addr = listener.local_addr().unwrap(); let t = thread::spawn(move || assert_ok!(listener.accept()).0); From 2155bb8e33913fa8284391d3ba189a78b87f74ba Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 21:35:28 -0600 Subject: [PATCH 17/21] fml --- tokio/tests/tcp_peek.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index 05dafb2a77e..2a5d2362067 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -20,6 +20,9 @@ async fn peek() { let t = thread::spawn(move || assert_ok!(listener.accept()).0); let left = net::TcpStream::connect(addr).unwrap(); + + left.set_nonblocking(true).unwrap(); + let mut right = t.join().unwrap(); let _ = right.write(&[1, 2, 3, 4]).unwrap(); From b5a3558ba5113dd47b70fabecc12be72abf331dc Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 21:41:15 -0600 Subject: [PATCH 18/21] lol --- tokio/tests/tcp_peek.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index 2a5d2362067..171db78343d 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -24,6 +24,9 @@ async fn peek() { left.set_nonblocking(true).unwrap(); let mut right = t.join().unwrap(); + + right.set_nonblocking(true).unwrap(); + let _ = right.write(&[1, 2, 3, 4]).unwrap(); let mut left: TcpStream = left.try_into().unwrap(); From 89fdc7163ac07699721154f6e4bb4dd8c7d6080a Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Mar 2025 21:49:10 -0600 Subject: [PATCH 19/21] lol --- tokio/tests/tcp_peek.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index 171db78343d..deb0028227e 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -14,8 +14,6 @@ use std::{io::Write, net}; async fn peek() { let listener = net::TcpListener::bind("127.0.0.1:0").unwrap(); - listener.set_nonblocking(true).unwrap(); - let addr = listener.local_addr().unwrap(); let t = thread::spawn(move || assert_ok!(listener.accept()).0); From 5e99a1b46cdcfb94e0f1ef6245d8d610ac2ad970 Mon Sep 17 00:00:00 2001 From: noah Date: Mon, 3 Mar 2025 19:39:58 -0600 Subject: [PATCH 20/21] make these lines shorter --- tokio/src/net/tcp/listener.rs | 4 +++- tokio/src/net/tcp/stream.rs | 4 +++- tokio/src/net/udp.rs | 4 +++- tokio/src/net/unix/datagram/socket.rs | 4 +++- tokio/src/net/unix/listener.rs | 4 +++- tokio/src/net/unix/stream.rs | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index 093b544881e..d29e6ee13a0 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -210,7 +210,9 @@ impl TcpListener { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, + /// and the behavior in that case may change in the future. + /// For example, it could panic. /// /// [`set_nonblocking`]: std::net::TcpListener::set_nonblocking /// diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 507476b016a..7c753741c44 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -174,7 +174,9 @@ impl TcpStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, + /// and the behavior in that case may change in the future. + /// For example, it could panic. /// /// [`set_nonblocking`]: std::net::TcpStream::set_nonblocking /// diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index 349ff16ceeb..044096eb6e0 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -193,7 +193,9 @@ impl UdpSocket { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, + /// and the behavior in that case may change in the future. + /// For example, it could panic. /// /// [`set_nonblocking`]: std::net::UdpSocket::set_nonblocking /// diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs index d68a4ba1d4d..4f1fb669526 100644 --- a/tokio/src/net/unix/datagram/socket.rs +++ b/tokio/src/net/unix/datagram/socket.rs @@ -450,7 +450,9 @@ impl UnixDatagram { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, + /// and the behavior in that case may change in the future. + /// For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixDatagram::set_nonblocking /// diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 76534562a26..996d3e1dced 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -107,7 +107,9 @@ impl UnixListener { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, + /// and the behavior in that case may change in the future. + /// For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixListener::set_nonblocking /// diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 8e5ceb01e13..3f3220cd813 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -792,7 +792,9 @@ impl UnixStream { /// will block the thread, which will cause unexpected behavior. /// Non-blocking mode can be set using [`set_nonblocking`]. /// - /// Passing a listener in blocking mode is always erroneous, and the behavior in that case may change in the future. For example, it could panic. + /// Passing a listener in blocking mode is always erroneous, + /// and the behavior in that case may change in the future. + /// For example, it could panic. /// /// [`set_nonblocking`]: std::os::unix::net::UnixStream::set_nonblocking /// From 3e84e6049368514d2336095a2c139fce56a664ad Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Tue, 4 Mar 2025 20:29:51 -0600 Subject: [PATCH 21/21] Update tokio/src/util/blocking_check.rs Co-authored-by: Carl Lerche --- tokio/src/util/blocking_check.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/src/util/blocking_check.rs b/tokio/src/util/blocking_check.rs index c45cbbdfd65..f7f35f6a1a8 100644 --- a/tokio/src/util/blocking_check.rs +++ b/tokio/src/util/blocking_check.rs @@ -13,7 +13,7 @@ pub(crate) fn check_socket_for_blocking(s: &S) -> crate::io::Result<()> sock.nonblocking()?, "Registering a blocking socket with the tokio runtime is unsupported. \ If you wish to do anyways, please add `--cfg tokio_allow_from_blocking_fd` to your \ - RUSTFLAGS. See 7172 for more details." + RUSTFLAGS. See github.com/tokio-rs/tokio/issues/7172 for details." ); }