chore: tweak blocking peer connections

This commit is contained in:
Michel de Graaf
2025-11-11 19:36:50 +01:00
parent bf7eb66e58
commit fb1e5eac07
+4 -22
View File
@@ -389,25 +389,9 @@ impl PeerActor {
match socket_addr { match socket_addr {
Ok(addr) => { Ok(addr) => {
if let Ok(stream) = TcpStream::connect(addr) { // Use connect_timeout to prevent blocking the thread for too long
if let Err(e) = stream.set_nonblocking(true) { let timeout = Duration::from_secs(5);
error!( match TcpStream::connect_timeout(&addr, timeout) {
"[peer:{}] Failed to set non-blocking: {}",
username, e
);
self.disconnect_with_error(e);
return false;
}
stream.set_nodelay(true).ok();
self.stream = Some(stream);
self.connection_state = ConnectionState::Connecting {
since: Instant::now(),
};
true
} else {
match TcpStream::connect(addr) {
Ok(stream) => { Ok(stream) => {
if let Err(e) = stream.set_nonblocking(true) { if let Err(e) = stream.set_nonblocking(true) {
error!( error!(
@@ -419,8 +403,7 @@ impl PeerActor {
} }
stream.set_nodelay(true).ok(); stream.set_nodelay(true).ok();
self.stream = Some(stream); self.stream = Some(stream);
self.connection_state = self.connection_state = ConnectionState::Connecting {
ConnectionState::Connecting {
since: Instant::now(), since: Instant::now(),
}; };
true true
@@ -431,7 +414,6 @@ impl PeerActor {
} }
} }
} }
}
Err(e) => { Err(e) => {
error!( error!(
"[peer:{}] Invalid socket address {}:{} - {}", "[peer:{}] Invalid socket address {}:{} - {}",