From 85e4cb3e4a7f5c0cab3c46936132544bd1a8ebd7 Mon Sep 17 00:00:00 2001 From: p11 Date: Tue, 15 Aug 2023 23:14:13 +0200 Subject: [PATCH] Quickfix: Clear pool if stuck for too long --- src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 801d817..a73707e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ use std::{ net::{TcpListener, TcpStream}, path::{Path, PathBuf}, sync::{Arc, Mutex}, + thread, + time::Duration, }; use data_stream::{ @@ -27,7 +29,7 @@ fn main() { }; let mut context = Context::default(); - let pool = ThreadPool::new(4); + let mut pool = ThreadPool::new(4); let mut args = env::args(); args.next(); @@ -43,6 +45,13 @@ fn main() { continue; }; + if pool.active_count() == pool.max_count() { + thread::sleep(Duration::from_secs(1)); + if pool.active_count() == pool.max_count() { + pool = ThreadPool::new(pool.max_count()) + } + } + context.handle_connection(&path, stream, &pool); } }