put timeout on collecting payloads

This commit is contained in:
asonix 2023-12-10 19:26:16 -06:00
parent 961de20a00
commit 7293628148

View file

@ -1,6 +1,7 @@
use std::{ use std::{
future::{ready, Ready}, future::{ready, Ready},
rc::Rc, rc::Rc,
time::Duration,
}; };
use actix_web::{ use actix_web::{
@ -18,10 +19,11 @@ async fn drain(rx: flume::Receiver<actix_web::dev::Payload>) {
let mut set = JoinSet::new(); let mut set = JoinSet::new();
while let Ok(payload) = rx.recv_async().await { while let Ok(payload) = rx.recv_async().await {
set.spawn_local(async move { // draining a payload is a best-effort task - if we can't collect in 2 minutes we bail
set.spawn_local(tokio::time::timeout(Duration::from_secs(120), async move {
let mut streamer = payload.into_streamer(); let mut streamer = payload.into_streamer();
while streamer.next().await.is_some() {} while streamer.next().await.is_some() {}
}); }));
let mut count = 0; let mut count = 0;