Skip to content
Snippets Groups Projects

fix: don't ignore all but the first resolved socket addresses

Merged Georgy Moshkin requested to merge gmoshkin/reduce-tcp-connect-logic-dubiousness into master
All threads resolved!
Files
3
@@ -169,11 +169,13 @@ impl TcpStream {
// If no error, then connection is established
};
// If this allocation panics the fd will still be closed
let result = Self {
fd: Rc::new(Cell::new(None)),
};
// Now TcpStream owns the fd and takes responsibility of closing it.
let fd = fd.into_inner();
return Ok(Self {
fd: Rc::new(Cell::new(Some(fd))),
});
result.fd.set(Some(fd.into_inner()));
return Ok(result);
}
#[inline(always)]
@@ -258,6 +260,8 @@ fn nonblocking_socket(kind: libc::c_int) -> io::Result<AutoCloseFd> {
/// A wrapper around a raw file descriptor, which automatically closes the
/// descriptor if dropped.
/// Use [`Self::into_inner`] to disable the automatic close on drop.
///
/// TODO: consider using [`std::os::fd::OwnedFd`] instead
struct AutoCloseFd(RawFd);
impl AutoCloseFd {
@@ -659,7 +663,7 @@ mod tests {
async fn read_timeout() {
let mut stream = TcpStream::connect_timeout("localhost", listen_port(), _10_SEC).unwrap();
// Read greeting
let mut buf = vec![0; 128];
let mut buf = vec![0; 4096];
assert_eq!(
stream
.read_exact(&mut buf)
@@ -843,10 +847,10 @@ mod tests {
unsafe { libc::close(fd) };
}
fn get_socket_fds() -> Vec<u32> {
fn get_socket_fds() -> HashSet<u32> {
use std::os::unix::fs::FileTypeExt;
let mut res = vec![];
let mut res = HashSet::new();
for entry in std::fs::read_dir("/dev/fd/").unwrap() {
let Ok(entry) = entry else {
continue;
@@ -862,9 +866,8 @@ mod tests {
// Yay rust!
let fd_str = fd_path.file_name().unwrap();
let fd: u32 = fd_str.to_str().unwrap().parse().unwrap();
res.push(fd);
res.insert(fd);
}
res.sort_unstable();
res
}
@@ -881,6 +884,7 @@ mod tests {
// XXX: this is a bit unreliable, because tarantool is spawning a bunch
// of other threads which may or may not be creating and closing fds,
// so we may want to remove this test at some point
assert_eq!(fds_before, fds_after)
let new_fds: Vec<_> = fds_after.difference(&fds_before).copied().collect();
assert!(dbg!(new_fds.is_empty()));
}
}
Loading