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

fix(core): socket being closed twice on Windows #1444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/trippy-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub enum IoOperation {
SetReusePort,
SetHeaderIncluded,
SetUnicastHopsV6,
Close,
WSACreateEvent,
WSARecvFrom,
WSAEventSelect,
Expand Down Expand Up @@ -121,7 +120,6 @@ impl Display for IoOperation {
Self::SetReusePort => write!(f, "set reuse port"),
Self::SetHeaderIncluded => write!(f, "set header included"),
Self::SetUnicastHopsV6 => write!(f, "set unicast hops v6"),
Self::Close => write!(f, "close"),
Self::WSACreateEvent => write!(f, "WSA create event"),
Self::WSARecvFrom => write!(f, "WSA recv from"),
Self::WSAEventSelect => write!(f, "WSA event select"),
Expand Down
5 changes: 0 additions & 5 deletions crates/trippy-core/src/net/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,6 @@ mod socket {
fn icmp_error_info(&mut self) -> IoResult<IpAddr> {
Ok(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
}
#[allow(clippy::unused_self, clippy::unnecessary_wraps)]
#[instrument(skip(self))]
fn close(&mut self) -> IoResult<()> {
Ok(())
}
}

impl From<&io::Error> for ErrorKind {
Expand Down
10 changes: 0 additions & 10 deletions crates/trippy-core/src/net/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ impl SocketImpl {
#[allow(clippy::redundant_closure_call)]
impl Drop for SocketImpl {
fn drop(&mut self) {
self.close().unwrap_or_default();
if self.ol.hEvent != -1 && self.ol.hEvent != 0 {
syscall!(WSACloseEvent(self.ol.hEvent), |res| { res == 0 }).unwrap_or_default();
}
Expand Down Expand Up @@ -579,15 +578,6 @@ impl Socket for SocketImpl {
)),
}
}

// Interestingly, Socket2 sockets don't seem to call closesocket on drop??
#[instrument(skip(self))]
fn close(&mut self) -> IoResult<()> {
syscall!(closesocket(self.inner.as_raw_socket() as _), |res| res
== SOCKET_ERROR)
.map_err(|err| IoError::Other(err, IoOperation::Close))
.map(|_| ())
}
}

// Note that we handle `WSAENOBUFS`, which can occurs when calling send_to()
Expand Down
1 change: 0 additions & 1 deletion crates/trippy-core/src/net/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ where
fn peer_addr(&mut self) -> Result<Option<SocketAddr>>;
fn take_error(&mut self) -> Result<Option<SocketError>>;
fn icmp_error_info(&mut self) -> Result<IpAddr>;
fn close(&mut self) -> Result<()>;
}

/// A socket error returned by `Socket::take_error`.
Expand Down
11 changes: 1 addition & 10 deletions crates/trippy-core/src/net/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ impl SourceAddr {
}?;
let sock_addr = SocketAddr::new(source_addr, 0);
match socket.bind(sock_addr) {
Ok(()) => {
socket.close()?;
Ok(source_addr)
}
Ok(()) => Ok(source_addr),
Err(_) => Err(InvalidSourceAddr(sock_addr.ip())),
}
}
Expand Down Expand Up @@ -161,9 +158,6 @@ mod tests {
.with(predicate::eq(expected_bind_addr))
.times(1)
.returning(|_| Ok(()));

mocket.expect_close().times(1).returning(|| Ok(()));

Ok(mocket)
});

Expand All @@ -186,9 +180,6 @@ mod tests {
.with(predicate::eq(expected_bind_addr))
.times(1)
.returning(|_| Ok(()));

mocket.expect_close().times(1).returning(|| Ok(()));

Ok(mocket)
});

Expand Down