Skip to content

Conversation

@Thomasdezeeuw
Copy link
Collaborator

Instead of the workaround where we use std::net::TcpStream.

Unfortunately Windows uses std::os::windows::io::RawSocket (u64), which
is different from the RawSocket that we define that uses
windows_sys::Win32::Networking::WinSock::SOCKET (usize). So the std lib
version gets ranamed to StdRawSocket.
// something we don't want. So check for that we have this
// `assert!`.
#[cfg(unix)]
assert!(raw >= 0, "tried to create a `Socket` with an invalid fd");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is a test for this assertion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test with the error message from std lib, don't think there is value is checking it twice.

Instead of the workaround where we use std::net::TcpStream.
@Thomasdezeeuw
Copy link
Collaborator Author

Panic message is different in 1.70 vs. current stable 🤦 I'll just change it to only check for the panic

It changed between 1.70 and current stable. Checking if the function
panics should be good enough.
@Thomasdezeeuw Thomasdezeeuw merged commit 39d3e34 into master Jul 4, 2025
47 checks passed
@Thomasdezeeuw Thomasdezeeuw deleted the ownedfd branch July 4, 2025 13:23
Comment on lines +90 to +91
// potentially close a fd it doesn't own. All of that isn't memory
// unsafe, so it's not desired but never memory unsafe or causes UB.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediate UB, but we consider it library UB because downstream effects can cause memory unsafety, e.g. by incorrectly touching mmap'ed fds.

https://doc.rust-lang.org/std/io/index.html#io-safety

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants