From 54c3096b248a60d87bafc888f8212adc20503104 Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Mon, 23 Oct 2023 09:45:46 -0500 Subject: [PATCH] document that we do not support EPOLLONESHOT and advise the use of EPOLLET, and add debug assert to check for EPOLLONESHOT --- tokio/src/io/async_fd.rs | 9 +++++++-- tokio/src/net/tcp/listener.rs | 9 +++++++-- tokio/src/net/unix/listener.rs | 9 +++++++-- tokio/src/runtime/io/registration.rs | 5 +++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tokio/src/io/async_fd.rs b/tokio/src/io/async_fd.rs index e7ef15053..12d6a0f5f 100644 --- a/tokio/src/io/async_fd.rs +++ b/tokio/src/io/async_fd.rs @@ -247,8 +247,13 @@ impl AsyncFd { /// /// These flags replace any epoll flags would normally set when registering the fd. /// - /// **Note**: This is an [unstable API][unstable]. The public API of this may break in 1.x - /// releases. + /// # Note + /// This API does not support the use of `EPOLLONESHOT`. + /// Users are strongly advised to use `EPOLLET` to prevent the tokio IO driver from receiving + /// spurious wakes. + /// + /// # Stability + /// This is an [unstable API][unstable]. The public API of this may break in 1.x releases. /// See [the documentation on unstable features][unstable] for details. /// /// [unstable]: crate#unstable-features diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index e455c76bc..0c6c1792a 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -244,8 +244,13 @@ impl TcpListener { /// /// These flags replace any epoll flags would normally set when registering the fd. /// - /// **Note**: This is an [unstable API][unstable]. The public API of this may break in 1.x - /// releases. + /// # Note + /// This API does not support the use of `EPOLLONESHOT`. + /// Users are strongly advised to use `EPOLLET` to prevent the tokio IO driver from receiving + /// spurious wakes. + /// + /// # Stability + /// This is an [unstable API][unstable]. The public API of this may break in 1.x releases. /// See [the documentation on unstable features][unstable] for details. /// /// [unstable]: crate#unstable-features diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 380c1e4ed..1686b59e9 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -118,8 +118,13 @@ impl UnixListener { /// /// These flags replace any epoll flags would normally set when registering the fd. /// - /// **Note**: This is an [unstable API][unstable]. The public API of this may break in 1.x - /// releases. + /// # Note + /// This API does not support the use of `EPOLLONESHOT`. + /// Users are strongly advised to use `EPOLLET` to prevent the tokio IO driver from receiving + /// spurious wakes. + /// + /// # Stability + /// This is an [unstable API][unstable]. The public API of this may break in 1.x releases. /// See [the documentation on unstable features][unstable] for details. /// /// [unstable]: crate#unstable-features diff --git a/tokio/src/runtime/io/registration.rs b/tokio/src/runtime/io/registration.rs index e6f27e044..3b9827bab 100644 --- a/tokio/src/runtime/io/registration.rs +++ b/tokio/src/runtime/io/registration.rs @@ -95,6 +95,11 @@ impl Registration { flags: u32, handle: scheduler::Handle, ) -> io::Result { + debug_assert!( + (flags & libc::EPOLLONESHOT as u32) == 0, + "Tokio does not support using EPOLLONESHOT in user-specified epoll flags" + ); + let shared = handle.driver().io().add_source_raw(io, flags)?; Ok(Registration { handle, shared })