feat: disable Nagle's algorithm for LP between nym-nodes (#6857)
This commit is contained in:
committed by
GitHub
parent
8de781f750
commit
e8410b2302
@@ -404,7 +404,7 @@ where
|
||||
};
|
||||
|
||||
// Connect to target gateway with timeout
|
||||
let stream = match timeout(Duration::from_secs(5), S::connect(target_addr)).await {
|
||||
let mut stream = match timeout(Duration::from_secs(5), S::connect(target_addr)).await {
|
||||
Ok(Ok(stream)) => stream,
|
||||
Ok(Err(e)) => {
|
||||
inc!("lp_forward_failed");
|
||||
@@ -422,6 +422,16 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
// Disable Nagle's algorithm: the forward stream carries small request/response
|
||||
// handshake packets, so we want them sent immediately rather than coalesced.
|
||||
if let Err(e) = stream.set_no_delay(true) {
|
||||
inc!("lp_forward_failed");
|
||||
return Err(LpHandlerError::ConnectionFailure {
|
||||
egress: target_addr,
|
||||
reason: format!("failed to set TCP_NODELAY: {e}"),
|
||||
});
|
||||
}
|
||||
|
||||
debug!("Opened persistent exit connection to {target_addr} for forwarding");
|
||||
self.exit_stream = Some((stream, target_addr));
|
||||
|
||||
|
||||
@@ -171,6 +171,14 @@ impl LpControlListener {
|
||||
}
|
||||
|
||||
fn handle_connection(&self, stream: tokio::net::TcpStream, remote_addr: SocketAddr) {
|
||||
// Disable Nagle's algorithm on the accepted socket so our responses are flushed
|
||||
// immediately rather than coalesced. This is the write side of every reply we send,
|
||||
// including handshake replies forwarded back to an entry gateway. Non-fatal: a valid
|
||||
// connection should still be served if the option can't be set.
|
||||
if let Err(e) = stream.set_nodelay(true) {
|
||||
warn!("failed to set TCP_NODELAY on accepted LP connection from {remote_addr}: {e}");
|
||||
}
|
||||
|
||||
if let Some(initiator_details) = self
|
||||
.nodes_handler_state
|
||||
.nodes
|
||||
|
||||
Reference in New Issue
Block a user