Skip to content
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

File fd leaked #229

Closed
xutianyi1999 opened this issue Jan 26, 2024 · 2 comments · Fixed by #245
Closed

File fd leaked #229

xutianyi1999 opened this issue Jan 26, 2024 · 2 comments · Fixed by #245

Comments

@xutianyi1999
Copy link

Version
└── monoio v0.2.1
├── monoio-macros v0.1.0 (proc-macro)

Platform
Linux DESKTOP-2CTP7F6 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
65536

Description
文件离开作用域后未被关闭,即使整个Runtime都已经被drop了
image

@ihciah
Copy link
Member

ihciah commented Jan 31, 2024

Thanks for reporting, we will try to reproduce and fix it.

@hxzhao527
Copy link
Contributor

文件离开作用域后未被关闭

预期之内. 在File::close中有说明, 这里不再赘述.
Work as expected. This is described in File::close and will not be repeated here.

/// Closes the file.
///
/// The method completes once the close operation has completed,
/// guaranteeing that resources associated with the file have been released.
///
/// If `close` is not called before dropping the file, the file is closed in
/// the background, but there is no guarantee as to **when** the close
/// operation will complete.
///
/// # Examples
///
/// ```no_run
/// use monoio::fs::File;
///
/// #[monoio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Open the file
/// let f = File::open("foo.txt").await?;
/// // Close the file
/// f.close().await?;
///
/// Ok(())
/// }
/// ```
pub async fn close(self) -> io::Result<()> {
self.fd.close().await;
Ok(())
}

即使整个Runtime都已经被drop了

预期之外. 上面的例子比较特殊, 虽然file离开作用域后确实有通过Drop提交Close, 但是由于最外层的future已经退出, 导致没有submit的时机. 在 #240 中补齐了这个submit.
Not expected. The above example is special in that while Close is indeed submitted via Drop after the file leaves the scope, but there is no timing for submit because the outermost future has already exited. This submit is made up in #240.

ihciah pushed a commit that referenced this issue Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants