diff --git a/monoio/src/driver/uring/mod.rs b/monoio/src/driver/uring/mod.rs index a2a06016..e170d12a 100644 --- a/monoio/src/driver/uring/mod.rs +++ b/monoio/src/driver/uring/mod.rs @@ -583,6 +583,8 @@ impl Drop for IoUringDriver { impl Drop for UringInner { fn drop(&mut self) { + // no need to wait for completion, as the kernel will clean up the ring asynchronically. + let _ = self.uring.submitter().submit(); unsafe { ManuallyDrop::drop(&mut self.uring); } diff --git a/monoio/tests/fs_file.rs b/monoio/tests/fs_file.rs index 98b5b959..43cffb84 100644 --- a/monoio/tests/fs_file.rs +++ b/monoio/tests/fs_file.rs @@ -22,6 +22,7 @@ async fn read_hello(file: &File) { async fn basic_read() { let mut tempfile = tempfile(); tempfile.write_all(HELLO).unwrap(); + tempfile.as_file_mut().sync_data().unwrap(); let file = File::open(tempfile.path()).await.unwrap(); read_hello(&file).await; @@ -31,6 +32,7 @@ async fn basic_read() { async fn basic_read_exact() { let mut tempfile = tempfile(); tempfile.write_all(HELLO).unwrap(); + tempfile.as_file_mut().sync_data().unwrap(); let file = File::open(tempfile.path()).await.unwrap(); let buf = Vec::with_capacity(HELLO.len()); @@ -49,6 +51,7 @@ async fn basic_write() { let file = File::create(tempfile.path()).await.unwrap(); file.write_at(HELLO, 0).await.0.unwrap(); + file.sync_all().await.unwrap(); let file = std::fs::read(tempfile.path()).unwrap(); assert_eq!(file, HELLO); @@ -60,6 +63,7 @@ async fn basic_write_all() { let file = File::create(tempfile.path()).await.unwrap(); file.write_all_at(HELLO, 0).await.0.unwrap(); + file.sync_all().await.unwrap(); let file = std::fs::read(tempfile.path()).unwrap(); assert_eq!(file, HELLO); @@ -69,6 +73,7 @@ async fn basic_write_all() { async fn cancel_read() { let mut tempfile = tempfile(); tempfile.write_all(HELLO).unwrap(); + tempfile.as_file_mut().sync_data().unwrap(); let file = File::open(tempfile.path()).await.unwrap(); @@ -82,6 +87,7 @@ async fn cancel_read() { async fn explicit_close() { let mut tempfile = tempfile(); tempfile.write_all(HELLO).unwrap(); + tempfile.as_file_mut().sync_data().unwrap(); let file = File::open(tempfile.path()).await.unwrap(); #[cfg(unix)] @@ -91,7 +97,7 @@ async fn explicit_close() { file.close().await.unwrap(); - assert_invalid_fd(fd); + assert_invalid_fd(fd, tempfile.as_file().metadata().unwrap()); } #[monoio::test_all] @@ -101,6 +107,7 @@ async fn drop_open() { // Do something else let file_w = File::create(tempfile.path()).await.unwrap(); file_w.write_at(HELLO, 0).await.0.unwrap(); + file_w.sync_all().await.unwrap(); let file = std::fs::read(tempfile.path()).unwrap(); assert_eq!(file, HELLO); @@ -125,7 +132,7 @@ fn drop_off_runtime() { let fd = file.as_raw_handle(); drop(file); - assert_invalid_fd(fd); + assert_invalid_fd(fd, tempfile.as_file().metadata().unwrap()); } #[monoio::test_all] @@ -158,13 +165,29 @@ async fn poll_once(future: impl std::future::Future) { .await; } -fn assert_invalid_fd(fd: RawFd) { +fn assert_invalid_fd(fd: RawFd, base: std::fs::Metadata) { use std::fs::File; #[cfg(unix)] - let mut f = unsafe { File::from_raw_fd(fd) }; + let f = unsafe { File::from_raw_fd(fd) }; #[cfg(windows)] - let mut f = unsafe { File::from_raw_handle(fd) }; - let mut buf = vec![]; - - assert!(f.read_to_end(&mut buf).is_err()); + let f = unsafe { File::from_raw_handle(fd) }; + + let meta = f.metadata(); + std::mem::forget(f); + + if let Ok(meta) = meta { + if !meta.is_file() { + return; + } + + #[cfg(unix)] + { + use std::os::unix::fs::MetadataExt; + let inode = meta.ino(); + let actual = base.ino(); + if inode == actual { + panic!(); + } + } + } }