limit client on number of streams that will be accepted

This commit is contained in:
godmodegalactus 2024-07-04 21:08:35 +02:00
parent 7d8a79950c
commit f7528c1c8b
No known key found for this signature in database
GPG Key ID: 22DA4A30887FDA3C
1 changed files with 6 additions and 1 deletions

View File

@ -110,12 +110,17 @@ impl Client {
{
let connection = connection.clone();
tokio::spawn(async move {
// limit client to respond to 128k streams in parallel
let semaphore = Arc::new(tokio::sync::Semaphore::new(128 * 1024));
loop {
let stream = connection.accept_uni().await;
let permit = semaphore.clone().acquire_owned().await.unwrap();
let stream: Result<RecvStream, ConnectionError> = connection.accept_uni().await;
match stream {
Ok(recv_stream) => {
let sender = message_sx_queue.clone();
tokio::spawn(async move {
//
let _permit = permit;
let message = recv_message(recv_stream, timeout).await;
match message {
Ok(message) => {