Skip to content

Commit e3fca10

Browse files
committed
fix: bump default max open files limit
1 parent 2b6552a commit e3fca10

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rproxy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pin-project = "1.1.10"
4848
pnet = "0.35.0"
4949
prometheus-client = { git = "https://github.com/0x416e746f6e/client_rust.git", branch = "nested-labels"}
5050
rand = { version = "0.9.2", optional = true }
51+
rlimit = "0.10.2"
5152
rustc-hash = "2.1.1"
5253
rustls = "0.23.32"
5354
rustls-pemfile = "2.2.0"

crates/rproxy/src/server.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub mod config;
2-
32
pub(crate) mod metrics;
43
pub(crate) mod proxy;
54

@@ -13,7 +12,7 @@ use tokio::{
1312
task::JoinHandle,
1413
};
1514
use tokio_util::sync::CancellationToken;
16-
use tracing::{error, info};
15+
use tracing::{error, info, warn};
1716

1817
use crate::{
1918
config::Config,
@@ -29,6 +28,8 @@ use crate::{
2928
utils::tls_certificate_validity_timestamps,
3029
};
3130

31+
const MAX_OPEN_FILES: u64 = 10240;
32+
3233
// Proxy ---------------------------------------------------------------
3334

3435
pub struct Server {}
@@ -38,6 +39,30 @@ impl Server {
3839
let canceller = Server::wait_for_shutdown_signal();
3940
let resetter = Server::wait_for_reset_signal(canceller.clone());
4041

42+
// try to set system limits
43+
match rlimit::getrlimit(rlimit::Resource::NOFILE) {
44+
Ok((mut soft, hard)) => {
45+
soft = std::cmp::max(soft, MAX_OPEN_FILES);
46+
soft = std::cmp::min(soft, hard);
47+
48+
if let Err(err) = rlimit::setrlimit(rlimit::Resource::NOFILE, soft, hard) {
49+
warn!(
50+
error = ?err,
51+
hard = hard,
52+
soft = soft,
53+
"Failed to set max open file limits",
54+
);
55+
}
56+
}
57+
58+
Err(err) => {
59+
warn!(
60+
error = ?err,
61+
"Failed to read max open file limits",
62+
);
63+
}
64+
}
65+
4166
// spawn metrics service
4267
let metrics = Arc::new(Metrics::new(config.metrics.clone()));
4368
{

0 commit comments

Comments
 (0)