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
Panic if an OwnedFd
carried a bad file descriptor
#124518
base: master
Are you sure you want to change the base?
Conversation
This should never happen, notify the user if it did happen anyway.
r? @ChrisDenton rustbot has assigned @ChrisDenton. Use |
The job Click to see the possible cause of the failure (guessed by this bot)
|
match cvt(libc::close(self.fd)) { | ||
Ok(_) => {}, | ||
Err(err) if err.raw_os_error() == Some(libc::EBADF) { | ||
panic!("`OwnedFd` held an invalid file descriptor"); |
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.
debug_assert_fd_is_open
(added in #124210) checks if the file descriptor actually existed. The reason that PR doesn't just check the result of close
is because a FUSE filesystem can return EBADF
from close
even if the fd actually exists.
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.
Hmmmmm. I see.
It's sad that there's no way to return an error here, would be nice if the user could somehow be alerted to this problem even in release mode.
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.
the right way to do that is to add an explicit fn close(self) -> Result
method. Whether everyone is onboard with that is a separate question.
This should never happen, notify the user if it did happen anyway.