Skip to content

Commit

Permalink
Don't close direct descriptor using close(2)
Browse files Browse the repository at this point in the history
That doesn't work.
  • Loading branch information
Thomasdezeeuw committed Aug 17, 2024
1 parent e2ba7cf commit a519844
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<D: Descriptor> Drop for AsyncFd<D> {
});
if let Err(err) = result {
log::warn!("error submitting close operation for a10::AsyncFd: {err}");
if let Err(err) = syscall!(close(self.fd())) {
if let Err(err) = D::close(self.fd()) {
log::warn!("error closing a10::AsyncFd: {err}");
}
}
Expand All @@ -202,6 +202,9 @@ impl<D: Descriptor> Drop for AsyncFd<D> {
pub trait Descriptor: private::Descriptor {}

pub(crate) mod private {
use std::os::fd::RawFd;
use std::io;

use crate::op::Submission;

pub(crate) trait Descriptor {
Expand All @@ -220,6 +223,8 @@ pub(crate) mod private {

/// Debug representation of the descriptor.
fn fmt_dbg() -> &'static str;

fn close(fd: RawFd) -> io::Result<()>;
}
}

Expand Down Expand Up @@ -249,6 +254,11 @@ impl private::Descriptor for File {
fn fmt_dbg() -> &'static str {
"file descriptor"
}

fn close(fd: RawFd) -> io::Result<()> {
syscall!(close(fd))?;
Ok(())
}
}

/// Direct descriptors are io_uring private file descriptors.
Expand Down Expand Up @@ -281,6 +291,12 @@ impl private::Descriptor for Direct {
fn fmt_dbg() -> &'static str {
"direct descriptor"
}

fn close(fd: RawFd) -> io::Result<()> {
// TODO: don't leak the the fd.
log::warn!("leaking direct descriptor {fd}");
Ok(())
}
}

// ToFd.
Expand Down

0 comments on commit a519844

Please sign in to comment.