Skip to content

Commit

Permalink
fix: socket leak in remote closing smol TCP sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op committed May 11, 2024
1 parent 2d9a3ca commit 6714e99
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions boltconn/src/transport/smol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ impl TcpConnTask {
}
}
}
if socket.state() == TcpState::CloseWait {
socket.close();
}
Ok(has_activity)
}

Expand Down Expand Up @@ -460,7 +457,7 @@ impl SmolStack {
// no double entry here, so theoretically there is no deadlock related to DashMap
for mut item in self.tcp_conn.iter_mut() {
let socket = self.socket_set.get_mut::<SmolTcpSocket>(item.handle);
if socket.state() == TcpState::Established || socket.state() == TcpState::SynSent {
if socket.may_send() || socket.state() == TcpState::SynSent {
match item.try_send(socket) {
Ok(v) => has_activity |= v,
Err(SmolError::Disconnected) => {
Expand All @@ -471,11 +468,14 @@ impl SmolStack {
item.abort_handle.cancel();
}
}
} else if socket.may_recv() && item.half_close_timeout.is_none() {
item.half_close_timeout = Some(Instant::now().add(Duration::from_secs(30)));
}

if socket.may_recv() {
// this async is a channel operation
has_activity |= item.try_recv(socket).await;
} else if socket.state() == TcpState::Established && item.half_close_timeout.is_none() {
} else if socket.may_send() && item.half_close_timeout.is_none() {
item.half_close_timeout = Some(Instant::now().add(Duration::from_secs(30)));
}
}
Expand Down

0 comments on commit 6714e99

Please sign in to comment.