-
Notifications
You must be signed in to change notification settings - Fork 0
7847: fs: implement tokio::fs::create_dir[_all] via io_uring #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,5 +47,23 @@ use std::path::Path; | |
| /// ``` | ||
| pub async fn create_dir_all(path: impl AsRef<Path>) -> io::Result<()> { | ||
| let path = path.as_ref().to_owned(); | ||
|
|
||
| #[cfg(all( | ||
| tokio_unstable, | ||
| feature = "io-uring", | ||
| feature = "rt", | ||
| feature = "fs", | ||
| target_os = "linux" | ||
| ))] | ||
| { | ||
| use crate::fs::create_dir_all_uring; | ||
|
|
||
| let handle = crate::runtime::Handle::current(); | ||
| let driver_handle = handle.inner.driver().io(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same concern as Severity: high 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-but-wont-fix; category:bug; feedback: The Augment AI reviewer is correct! io_uring support is experimental/unstable in Tokio, so the developer should opt-in for it. It is an application error if io_uring is requested but the IO driver is not enabled. Returning the error would tell the developer what (s)he needs to do. Falling back to asyncify() will hide the problem and leave the developer believing that IO Uring is in use. |
||
| if driver_handle.check_and_init(io_uring::opcode::MkDirAt::CODE)? { | ||
| return create_dir_all_uring(&path).await; | ||
| } | ||
| } | ||
|
|
||
| asyncify(move || std::fs::create_dir_all(path)).await | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #[cfg(all( | ||
| tokio_unstable, | ||
| feature = "io-uring", | ||
| feature = "rt", | ||
| feature = "fs", | ||
| target_os = "linux" | ||
| ))] | ||
| use crate::runtime::driver::op::Op; | ||
| use std::ffi::OsStr; | ||
| use std::io; | ||
| use std::os::unix::ffi::OsStrExt; | ||
| use std::path::Path; | ||
|
|
||
| pub(crate) async fn create_dir_all_uring(path: &Path) -> io::Result<()> { | ||
| if path == Path::new("") { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // First, check if the path exists. | ||
| if mkdir_parent_missing(path).await? { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // Otherwise, we must create its parents. | ||
| // For /a/b/c/d, we must first try /a/b/c, /a/b, /a, and /. | ||
| // Hence, we can iterate over the positions of / in reverse, | ||
| // finding the first / that appears after a directory that already exists. | ||
| // | ||
| // For example, suppose /a exists, but none of its children. | ||
| // The creation of /a/b will be successful. | ||
| // Hence, first_valid_separator_pos = 4. | ||
| let mut first_valid_separator_pos = None; | ||
| let path_bytes = path.as_os_str().as_bytes(); | ||
| for (separator_pos, _) in path_bytes | ||
| .iter() | ||
| .enumerate() | ||
| .rev() | ||
| .filter(|(_, &byte)| byte == b'/') | ||
| { | ||
| let parent_bytes = &path_bytes[..separator_pos]; | ||
| let parent_str = OsStr::from_bytes(parent_bytes); | ||
| let parent_path = Path::new(parent_str); | ||
| if mkdir_parent_missing(parent_path).await? { | ||
|
Comment on lines
+33
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The manual byte-level manipulation of paths using For example,
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:useful; category:bug; feedback: The Gemini AI reviewer is correct! There is no need to do this manual parsing of the file path. The PR author should use std::fs::Path and PathBuf instead. |
||
| first_valid_separator_pos = Some(separator_pos); | ||
| break; | ||
| } | ||
| } | ||
| let first_valid_separator_pos = first_valid_separator_pos.unwrap_or(0); | ||
|
|
||
| // Once we have found the correct /, | ||
| // we can iterate the remaining components in the forward direction. | ||
| // | ||
| // In the example /a/b/c/d path, there is only one remaining /, after c. | ||
| // Hence, we first create /a/b/c. | ||
| // | ||
| // TODO: We're attempting to create all directories sequentially. | ||
| // This would benefit from batching. | ||
|
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! If there are many directories to be created using batching may be better but this should be benchmarked first and implemented in a follow-up if needed. |
||
| for (separator_pos, _) in path_bytes | ||
| .iter() | ||
| .enumerate() | ||
| .skip(first_valid_separator_pos + 1) | ||
| .filter(|(_, &byte)| byte == b'/') | ||
| { | ||
| let parent_path = Path::new(OsStr::from_bytes(&path_bytes[..separator_pos])); | ||
| mkdir_parent_created(parent_path).await?; | ||
| } | ||
|
|
||
| // We must finally create the last path (/a/b/c/d in our example). | ||
| mkdir_parent_created(path).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| async fn mkdir_parent_missing(path: &Path) -> io::Result<bool> { | ||
| match Op::mkdir(path)?.await { | ||
| Ok(()) => Ok(true), | ||
| Err(ref e) if e.kind() == io::ErrorKind::NotFound => Ok(false), | ||
| // TODO: replace with uring-based statx | ||
| Err(_) if crate::fs::metadata(path).await?.is_dir() => Ok(true), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback to Consider ensuring that all file system operations within the
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-but-wont-fix; category:bug; feedback: The Gemini AI reviewer is correct! The statx (file metadata) is not yet implemented for io-uring, but IO_Uring support is introduced into Tokio feature by feature. This PR is about create_dir. A follow-up PR should be about statx |
||
| Err(e) => Err(e), | ||
|
Comment on lines
+73
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metadata fallback currently clobbers the original In Lines 78 and 87, metadata is evaluated with Suggested fix async fn mkdir_parent_missing(path: &Path) -> io::Result<bool> {
match Op::mkdir(path)?.await {
Ok(()) => Ok(true),
Err(ref e) if e.kind() == io::ErrorKind::NotFound => Ok(false),
// TODO: replace with uring-based statx
- Err(_) if crate::fs::metadata(path).await?.is_dir() => Ok(true),
- Err(e) => Err(e),
+ Err(e) => match crate::fs::metadata(path).await {
+ Ok(metadata) if metadata.is_dir() => Ok(true),
+ _ => Err(e),
+ },
}
}
async fn mkdir_parent_created(path: &Path) -> io::Result<()> {
match Op::mkdir(path)?.await {
Ok(()) => Ok(()),
// TODO: replace with uring-based statx
- Err(_) if crate::fs::metadata(path).await?.is_dir() => Ok(()),
- Err(e) => Err(e),
+ Err(e) => match crate::fs::metadata(path).await {
+ Ok(metadata) if metadata.is_dir() => Ok(()),
+ _ => Err(e),
+ },
}
}Also applies to: 83-88 🤖 Prompt for AI Agents
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:bug; feedback: The CodeRabbit AI reviewer is correct! If the metadata() calls errors then it will hide the original error. Better error handling is needed in this case to combine the errors or at least show the original error. |
||
| } | ||
| } | ||
|
|
||
| async fn mkdir_parent_created(path: &Path) -> io::Result<()> { | ||
| match Op::mkdir(path)?.await { | ||
| Ok(()) => Ok(()), | ||
| // TODO: replace with uring-based statx | ||
| Err(_) if crate::fs::metadata(path).await?.is_dir() => Ok(()), | ||
| Err(e) => Err(e), | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| use super::utils::cstr; | ||
|
|
||
| use crate::runtime::driver::op::{CancelData, Cancellable, Completable, CqeResult, Op}; | ||
|
|
||
| use io_uring::{opcode, types}; | ||
| use std::ffi::CString; | ||
| use std::io; | ||
| use std::io::Error; | ||
| use std::path::Path; | ||
|
|
||
| #[derive(Debug)] | ||
| pub(crate) struct Mkdir { | ||
| /// This field will be read by the kernel during the operation, so we | ||
| /// need to ensure it is valid for the entire duration of the operation. | ||
| #[allow(dead_code)] | ||
| path: CString, | ||
| } | ||
|
|
||
| impl Completable for Mkdir { | ||
| type Output = io::Result<()>; | ||
|
|
||
| fn complete(self, cqe: CqeResult) -> Self::Output { | ||
| cqe.result.map(|_| ()) | ||
| } | ||
|
|
||
| fn complete_with_error(self, err: Error) -> Self::Output { | ||
| Err(err) | ||
| } | ||
| } | ||
|
|
||
| impl Cancellable for Mkdir { | ||
| fn cancel(self) -> CancelData { | ||
| CancelData::Mkdir(self) | ||
| } | ||
| } | ||
|
|
||
| impl Op<Mkdir> { | ||
| /// Submit a request to create a directory. | ||
| pub(crate) fn mkdir(path: &Path) -> io::Result<Self> { | ||
| let path = cstr(path)?; | ||
|
|
||
| let mkdir_op = opcode::MkDirAt::new(types::Fd(libc::AT_FDCWD), path.as_ptr()) | ||
| .mode(0o777) | ||
| .build(); | ||
|
|
||
| // SAFETY: Parameters are valid for the entire duration of the operation | ||
| Ok(unsafe { Op::new(mkdir_op, Mkdir { path }) }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub(crate) mod mkdir; | ||
| pub(crate) mod open; | ||
| pub(crate) mod read; | ||
| pub(crate) mod utils; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,168 @@ | ||||||||||||||||||||||||||||||||||||||||
| //! Uring mkdir operations tests. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #![cfg(all( | ||||||||||||||||||||||||||||||||||||||||
| tokio_unstable, | ||||||||||||||||||||||||||||||||||||||||
| feature = "io-uring", | ||||||||||||||||||||||||||||||||||||||||
| feature = "rt", | ||||||||||||||||||||||||||||||||||||||||
| feature = "fs", | ||||||||||||||||||||||||||||||||||||||||
| target_os = "linux" | ||||||||||||||||||||||||||||||||||||||||
| ))] | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| use futures::FutureExt; | ||||||||||||||||||||||||||||||||||||||||
| use std::future::poll_fn; | ||||||||||||||||||||||||||||||||||||||||
| use std::future::Future; | ||||||||||||||||||||||||||||||||||||||||
| use std::pin::pin; | ||||||||||||||||||||||||||||||||||||||||
| use std::sync::mpsc; | ||||||||||||||||||||||||||||||||||||||||
| use std::task::Poll; | ||||||||||||||||||||||||||||||||||||||||
| use std::time::Duration; | ||||||||||||||||||||||||||||||||||||||||
| use tokio::runtime::{Builder, Runtime}; | ||||||||||||||||||||||||||||||||||||||||
| use tokio_test::assert_pending; | ||||||||||||||||||||||||||||||||||||||||
| use tokio_util::task::TaskTracker; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| fn multi_rt(n: usize) -> Box<dyn Fn() -> Runtime> { | ||||||||||||||||||||||||||||||||||||||||
| Box::new(move || { | ||||||||||||||||||||||||||||||||||||||||
| Builder::new_multi_thread() | ||||||||||||||||||||||||||||||||||||||||
| .worker_threads(n) | ||||||||||||||||||||||||||||||||||||||||
| .enable_all() | ||||||||||||||||||||||||||||||||||||||||
| .build() | ||||||||||||||||||||||||||||||||||||||||
| .unwrap() | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| fn current_rt() -> Box<dyn Fn() -> Runtime> { | ||||||||||||||||||||||||||||||||||||||||
| Box::new(|| Builder::new_current_thread().enable_all().build().unwrap()) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| fn rt_combinations() -> Vec<Box<dyn Fn() -> Runtime>> { | ||||||||||||||||||||||||||||||||||||||||
| vec![ | ||||||||||||||||||||||||||||||||||||||||
| current_rt(), | ||||||||||||||||||||||||||||||||||||||||
| multi_rt(1), | ||||||||||||||||||||||||||||||||||||||||
| multi_rt(2), | ||||||||||||||||||||||||||||||||||||||||
| multi_rt(8), | ||||||||||||||||||||||||||||||||||||||||
| multi_rt(64), | ||||||||||||||||||||||||||||||||||||||||
| multi_rt(256), | ||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||
| fn shutdown_runtime_while_performing_io_uring_ops() { | ||||||||||||||||||||||||||||||||||||||||
| fn run(rt: Runtime) { | ||||||||||||||||||||||||||||||||||||||||
| let (done_tx, done_rx) = mpsc::channel(); | ||||||||||||||||||||||||||||||||||||||||
| let workdir = tempfile::tempdir().unwrap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| rt.spawn(async move { | ||||||||||||||||||||||||||||||||||||||||
| // spawning a bunch of uring operations. | ||||||||||||||||||||||||||||||||||||||||
| for i in 0..usize::MAX { | ||||||||||||||||||||||||||||||||||||||||
| let child = workdir.path().join(format!("{i}")); | ||||||||||||||||||||||||||||||||||||||||
| tokio::spawn(async move { | ||||||||||||||||||||||||||||||||||||||||
| let mut fut = pin!(tokio::fs::create_dir(&child)); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| poll_fn(|cx| { | ||||||||||||||||||||||||||||||||||||||||
| assert_pending!(fut.as_mut().poll(cx)); | ||||||||||||||||||||||||||||||||||||||||
| Poll::<()>::Pending | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
| .await; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| fut.await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
At Line 61, the assertion is executed on every Suggested fix- poll_fn(|cx| {
- assert_pending!(fut.as_mut().poll(cx));
- Poll::<()>::Pending
- })
- .await;
-
- fut.await.unwrap();
+ let mut first_poll = true;
+ poll_fn(|cx| {
+ if first_poll {
+ assert_pending!(fut.as_mut().poll(cx));
+ first_poll = false;
+ }
+ Poll::<()>::Pending
+ })
+ .await;🤖 Prompt for AI Agents
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:bug; feedback: The CodeRabbit AI reviewer is correct! The test assumes that the poll_fn will be called just once because the handle should be aborted after the first poll but due to timings the poll_fn may be called more than once and the assertion will fail on the second run. The test should be improved to not depend on racing. |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Avoid busy looping. | ||||||||||||||||||||||||||||||||||||||||
| tokio::task::yield_now().await; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| std::thread::spawn(move || { | ||||||||||||||||||||||||||||||||||||||||
| rt.shutdown_timeout(Duration::from_millis(300)); | ||||||||||||||||||||||||||||||||||||||||
| done_tx.send(()).unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| done_rx.recv().unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| for rt in rt_combinations() { | ||||||||||||||||||||||||||||||||||||||||
| run(rt()); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||
| fn create_many_directories() { | ||||||||||||||||||||||||||||||||||||||||
| fn run(rt: Runtime) { | ||||||||||||||||||||||||||||||||||||||||
| let workdir = tempfile::tempdir().unwrap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| rt.block_on(async move { | ||||||||||||||||||||||||||||||||||||||||
| const N_CHILDREN: usize = 10_000; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let tracker = TaskTracker::new(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| for i in 0..N_CHILDREN { | ||||||||||||||||||||||||||||||||||||||||
| let child = workdir.path().join(format!("{i}")); | ||||||||||||||||||||||||||||||||||||||||
| tracker.spawn(async move { | ||||||||||||||||||||||||||||||||||||||||
| tokio::fs::create_dir(&child).await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| tracker.close(); | ||||||||||||||||||||||||||||||||||||||||
| tracker.wait().await; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let mut dir_iter = tokio::fs::read_dir(workdir.path()).await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| let mut child_count = 0; | ||||||||||||||||||||||||||||||||||||||||
| while dir_iter.next_entry().await.unwrap().is_some() { | ||||||||||||||||||||||||||||||||||||||||
| child_count += 1; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| assert_eq!(child_count, N_CHILDREN); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| for rt in rt_combinations() { | ||||||||||||||||||||||||||||||||||||||||
| run(rt()); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[tokio::test] | ||||||||||||||||||||||||||||||||||||||||
| async fn create_dir_all_edge_cases() { | ||||||||||||||||||||||||||||||||||||||||
| let workdir = tempfile::tempdir().unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| let workdir_path = workdir.path(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| tokio::fs::create_dir_all(workdir.path()).await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let nested_path = workdir_path.join("foo").join("bar"); | ||||||||||||||||||||||||||||||||||||||||
| tokio::fs::create_dir_all(&nested_path).await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| assert!(nested_path.is_dir()); | ||||||||||||||||||||||||||||||||||||||||
| tokio::fs::create_dir_all(nested_path.parent().unwrap()) | ||||||||||||||||||||||||||||||||||||||||
| .await | ||||||||||||||||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| tokio::fs::create_dir_all(&nested_path).await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let slash_trailing = workdir_path.join("./baz/qux//"); | ||||||||||||||||||||||||||||||||||||||||
| tokio::fs::create_dir_all(&slash_trailing).await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
| assert!(slash_trailing.is_dir()); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[tokio::test] | ||||||||||||||||||||||||||||||||||||||||
| async fn cancel_op_future() { | ||||||||||||||||||||||||||||||||||||||||
| let workdir = tempfile::tempdir().unwrap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); | ||||||||||||||||||||||||||||||||||||||||
| let handle = tokio::spawn(async move { | ||||||||||||||||||||||||||||||||||||||||
| poll_fn(|cx| { | ||||||||||||||||||||||||||||||||||||||||
| let child = workdir.path().join("child"); | ||||||||||||||||||||||||||||||||||||||||
| let fut = tokio::fs::create_dir(&child); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // If io_uring is enabled (and not falling back to the thread pool), | ||||||||||||||||||||||||||||||||||||||||
| // the first poll should return Pending. | ||||||||||||||||||||||||||||||||||||||||
| let _pending = pin!(fut).poll_unpin(cx); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+146
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because Suggested fix- poll_fn(|cx| {
- let child = workdir.path().join("child");
- let fut = tokio::fs::create_dir(&child);
-
- // If io_uring is enabled (and not falling back to the thread pool),
- // the first poll should return Pending.
- let _pending = pin!(fut).poll_unpin(cx);
-
- tx.send(()).unwrap();
-
- Poll::<()>::Pending
- })
+ let child = workdir.path().join("child");
+ let mut fut = pin!(tokio::fs::create_dir(&child));
+ let mut first_poll = true;
+ poll_fn(|cx| {
+ if first_poll {
+ assert_pending!(fut.as_mut().poll(cx));
+ first_poll = false;
+ tx.send(()).unwrap();
+ }
+ Poll::<()>::Pending
+ })
.await;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:bug; feedback: The CodeRabbit AI reviewer is correct! The test assumes that the poll_fn will be called just once because the handle should be aborted after the first poll but due to timings the poll_fn may be called more than once and then the a new future will be created. This does not do any harm but it is confusing |
||||||||||||||||||||||||||||||||||||||||
| tx.send(()).unwrap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Poll::<()>::Pending | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
| .await; | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Wait for the first poll | ||||||||||||||||||||||||||||||||||||||||
| rx.recv().await.unwrap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| handle.abort(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let res = handle.await.unwrap_err(); | ||||||||||||||||||||||||||||||||||||||||
| assert!(res.is_cancelled()); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle.inner.driver().io()will panic if the runtime was built without IO enabled (i.e.,enable_io/enable_allnot called), which would be a behavior change vs theasyncifyfallback. Consider guarding this socreate_dirstill falls back cleanly when IO is disabled at runtime.Severity: high
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:good-but-wont-fix; category:bug; feedback: The Augment AI reviewer is correct! io_uring support is experimental/unstable in Tokio, so the developer should opt-in for it. It is an application error if io_uring is requested but the IO driver is not enabled. Returning the error would tell the developer what (s)he needs to do. Falling back to asyncify() will hide the problem and leave the developer believing that IO Uring is in use.