limit client on number of streams that will be accepted
This commit is contained in:
parent
7d8a79950c
commit
f7528c1c8b
|
@ -110,12 +110,17 @@ impl Client {
|
||||||
{
|
{
|
||||||
let connection = connection.clone();
|
let connection = connection.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
// limit client to respond to 128k streams in parallel
|
||||||
|
let semaphore = Arc::new(tokio::sync::Semaphore::new(128 * 1024));
|
||||||
loop {
|
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 {
|
match stream {
|
||||||
Ok(recv_stream) => {
|
Ok(recv_stream) => {
|
||||||
let sender = message_sx_queue.clone();
|
let sender = message_sx_queue.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
//
|
||||||
|
let _permit = permit;
|
||||||
let message = recv_message(recv_stream, timeout).await;
|
let message = recv_message(recv_stream, timeout).await;
|
||||||
match message {
|
match message {
|
||||||
Ok(message) => {
|
Ok(message) => {
|
||||||
|
|
Loading…
Reference in New Issue