Bound WebSocket upgrade handshake duration (#722)

* Bound WebSocket upgrade handshake duration

* Document changed function contracts
This commit is contained in:
jahvari authored and GitHub committed 2026-11-07 12:43:08 +08:00
1 parent 134008e0e9
commit 474fbc7de4
2 files changed
+4 -2

No files matched your search

+2 -1
View File
@@ -419,6 +419,7 @@ async fn handle_connection(
});
}
/// Prepares a TCP or WebSocket relay stream and begins pairing.
async fn make_pair(
stream: TcpStream,
mut addr: SocketAddr,
@@ -452,7 +453,7 @@ async fn make_pair(
}
Ok(response)
};
let ws_stream = tokio_tungstenite::accept_hdr_async(stream, callback).await?;
let ws_stream = timeout(30_000, tokio_tungstenite::accept_hdr_async(stream, callback)).await??;
make_pair_(ws_stream, addr, key, limiter).await;
} else {
make_pair_(FramedStream::from(stream, addr), addr, key, limiter).await;
+2 -1
View File
@@ -1216,6 +1216,7 @@ impl RendezvousServer {
});
}
/// Processes rendezvous messages on an accepted TCP or WebSocket connection.
#[inline]
async fn handle_listener_inner(
&mut self,
@@ -1251,7 +1252,7 @@ impl RendezvousServer {
}
Ok(response)
};
let ws_stream = tokio_tungstenite::accept_hdr_async(stream, callback).await?;
let ws_stream = timeout(30_000, tokio_tungstenite::accept_hdr_async(stream, callback)).await??;
let (a, mut b) = ws_stream.split();
sink = Some(Sink::Ws(a));
while let Ok(Some(Ok(msg))) = timeout(30_000, b.next()).await {