File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ pub(crate) struct Proxy {
3232 pub default_action : String ,
3333 pub upstream : HashMap < String , Upstream > ,
3434 pub via : ViaUpstream ,
35- pub maxclients : Arc < Semaphore > ,
35+ pub maxclients : Arc < Semaphore < > > ,
3636 //pub maxclients: usize,
3737}
3838
Original file line number Diff line number Diff line change @@ -16,15 +16,21 @@ pub(crate) async fn proxy(config: Arc<Proxy>) -> Result<(), Box<dyn Error>> {
1616 config. name, config. maxclients
1717 ) ;
1818
19+ // Put the drop inside the tokio::spawn after the call to accept
1920 loop {
21+
2022 let thread_proxy = config. clone ( ) ;
23+ let permit = config. maxclients . clone ( ) . acquire_owned ( ) . await . unwrap ( ) ;
24+ info ! ( "permit.num_permits {:?}" , permit. num_permits( ) ) ;
25+
2126 match listener. accept ( ) . await {
2227 Err ( err) => {
2328 error ! ( "Failed to accept connection: {}" , err) ;
2429 return Err ( Box :: new ( err) ) ;
2530 }
2631 Ok ( ( stream, _) ) => {
2732 tokio:: spawn ( async move {
33+ drop ( permit) ;
2834 match accept ( stream, thread_proxy) . await {
2935 Ok ( _) => {
3036 //debug!("Accepted permit {:?}", permit);
@@ -40,8 +46,6 @@ pub(crate) async fn proxy(config: Arc<Proxy>) -> Result<(), Box<dyn Error>> {
4046}
4147
4248async fn accept ( inbound : TcpStream , proxy : Arc < Proxy > ) -> Result < ( ) , Box < dyn Error > > {
43- //let permit = proxy.maxclients.clone().acquire_owned().await.unwrap();
44- //info!("permit.num_permits {:?}", permit.num_permits());
4549
4650 if proxy. default_action . contains ( "health" ) {
4751 debug ! ( "Health check request" )
You can’t perform that action at this time.
0 commit comments