Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(router): server configuration addition (#11029)

Shivansh Mathur9445b1008947
diff --git a/config/config.example.toml b/config/config.example.toml
index 870b11d2bb..1b935b652f 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -11,11 +11,15 @@ application_source = "main"
[server]
port = 8080
host = "127.0.0.1"
+workers = 10 # Number of worker threads to handle requests (defaults to physical CPU count)
# This is the grace time (in seconds) given to the actix-server to stop the execution
# For more details: https://actix.rs/docs/server/#graceful-shutdown
shutdown_timeout = 30
# HTTP Request body limit. Defaults to 32kB
request_body_limit = 32_768
+keep_alive = 5 # Keep-alive timeout in seconds
+client_request_timeout = 5000 # Client request timeout in milliseconds
+client_disconnect_timeout = 1000 # Client disconnect timeout in milliseconds
# HTTPS Server Configuration
# Self-signed Private Key and Certificate can be generated with mkcert for local development
diff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.toml
index 8681ff8360..d2f7c193da 100644
--- a/config/deployments/env_specific.toml
+++ b/config/deployments/env_specific.toml
@@ -300,6 +300,12 @@ host = "127.0.0.1"
shutdown_timeout = 30
# HTTP Request body limit. Defaults to 32kB
request_body_limit = 32_768
+# Keep-alive timeout in seconds
+keep_alive = 5
+# Client request timeout in milliseconds
+client_request_timeout = 5000
+# Client disconnect timeout in milliseconds
+client_disconnect_timeout = 1000
# HTTPS Server Configuration
# Self-signed Private Key and Certificate can be generated with mkcert for local development
diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs
index 654949f250..14c4298e76 100644
--- a/crates/router/src/configs/defaults.rs
+++ b/crates/router/src/configs/defaults.rs
@@ -11,6 +11,9 @@ impl Default for super::settings::Server {
host: "localhost".into(),
request_body_limit: 16 * 1024, // POST request body is limited to 16KiB
shutdown_timeout: 30,
+ keep_alive: 5,
+ client_request_timeout: 5000,
+ client_disconnect_timeout: 1000,
#[cfg(feature = "tls")]
tls: None,
}
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 066e0b47bd..afe4b67e13 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -823,6 +823,9 @@ pub struct Server {
pub host: String,
pub request_body_limit: usize,
pub shutdown_timeout: u64,
+ pub keep_alive: u64,
+ pub client_request_timeout: u64,
+ pub client_disconnect_timeout: u64,
#[cfg(feature = "tls")]
pub tls: Option<ServerTls>,
}
diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs
index f268bedd9c..de87a3b3b1 100644
--- a/crates/router/src/lib.rs
+++ b/crates/router/src/lib.rs
@@ -292,7 +292,14 @@ pub async fn start_server(conf: settings::Settings<SecuredSecret>) -> Applicatio
actix_web::HttpServer::new(move || mk_app(state.clone(), request_body_limit))
.bind((server.host.as_str(), server.port))?
.workers(server.workers)
- .shutdown_timeout(server.shutdown_timeout);
+ .shutdown_timeout(server.shutdown_timeout)
+ .keep_alive(Some(std::time::Duration::from_secs(server.keep_alive)))
+ .client_request_timeout(std::time::Duration::from_millis(
+ server.client_request_timeout,
+ ))
+ .client_disconnect_timeout(std::time::Duration::from_millis(
+ server.client_disconnect_timeout,
+ ));
#[cfg(feature = "tls")]
let server = match server.tls {