Skip to content

Commit 9adb9b9

Browse files
committed
Use now the right combo of permit and drop for connection limits
1 parent 2a9c5f1 commit 9adb9b9

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

container-files/etc/l4p/config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ servers:
1616
sni:
1717
www.test1.com: proxy-via
1818
default: echo
19-
# note yet implemented
20-
maxclients: 2
19+
maxclients: 3
2120
via:
2221
*viaanchor
2322

src/servers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

src/servers/protocol/tcp.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,35 @@ pub(crate) async fn proxy(config: Arc<Proxy>) -> Result<(), Box<dyn Error>> {
1717
);
1818

1919
// Put the drop inside the tokio::spawn after the call to accept
20-
loop {
20+
// Big thanks to alice from https://users.rust-lang.org/
2121

22+
loop {
2223
let thread_proxy = config.clone();
2324
let permit = config.maxclients.clone().acquire_owned().await.unwrap();
24-
info!("permit.num_permits {:?}", permit.num_permits());
25-
25+
2626
match listener.accept().await {
2727
Err(err) => {
2828
error!("Failed to accept connection: {}", err);
2929
return Err(Box::new(err));
3030
}
3131
Ok((stream, _)) => {
3232
tokio::spawn(async move {
33-
drop(permit);
3433
match accept(stream, thread_proxy).await {
3534
Ok(_) => {
36-
//debug!("Accepted permit {:?}", permit);
35+
debug!("Accepted permit {:?}", permit);
3736
}
3837
Err(err) => {
3938
error!("Relay thread returned an error: {}", err);
4039
}
4140
};
41+
drop(permit);
4242
});
4343
}
4444
}
4545
}
4646
}
4747

4848
async fn accept(inbound: TcpStream, proxy: Arc<Proxy>) -> Result<(), Box<dyn Error>> {
49-
5049
if proxy.default_action.contains("health") {
5150
debug!("Health check request")
5251
} else {

0 commit comments

Comments
 (0)