From dd700947195ae5569c91359b90046b7868d755af Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 21 Feb 2026 15:15:26 +0000 Subject: [PATCH] feat: Make `max_active_txns` actually configurable --- conduwuit-example.toml | 9 +++++++++ src/api/server/send.rs | 6 +----- src/core/config/mod.rs | 13 +++++++++++++ src/service/transaction_ids/mod.rs | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 13412d457..9807746ac 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -290,6 +290,15 @@ # #max_fetch_prev_events = 192 +# How many incoming federation transactions the server is willing to be +# processing at any given time before it becomes overloaded and starts +# rejecting further transactions until some slots become available. +# +# Setting this value too low or too high may result in unstable +# federation, and setting it too high may cause runaway resource usage. +# +#max_concurrent_inbound_transactions = 150 + # Default/base connection timeout (seconds). This is used only by URL # previews and update/news endpoint checks. # diff --git a/src/api/server/send.rs b/src/api/server/send.rs index 0cfeb1c14..a1687d41c 100644 --- a/src/api/server/send.rs +++ b/src/api/server/send.rs @@ -151,11 +151,7 @@ async fn process_inbound_transaction( .filter_map(Result::ok) .stream(); - info!( - pdus = body.pdus.len(), - edus = body.edus.len(), - "Processing transaction", - ); + info!(pdus = body.pdus.len(), edus = body.edus.len(), "Processing transaction",); let Ok(results) = handle(&services, &client, body.origin(), txn_start_time, pdus, edus).await else { // TODO: handle this properly. The channel doesn't like being closed with no diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index e3f88a210..993f455d2 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -368,6 +368,17 @@ pub struct Config { #[serde(default = "default_max_fetch_prev_events")] pub max_fetch_prev_events: u16, + /// How many incoming federation transactions the server is willing to be + /// processing at any given time before it becomes overloaded and starts + /// rejecting further transactions until some slots become available. + /// + /// Setting this value too low or too high may result in unstable + /// federation, and setting it too high may cause runaway resource usage. + /// + /// default: 150 + #[serde(default = "default_max_concurrent_inbound_transactions")] + pub max_concurrent_inbound_transactions: usize, + /// Default/base connection timeout (seconds). This is used only by URL /// previews and update/news endpoint checks. /// @@ -2540,6 +2551,8 @@ fn default_pusher_idle_timeout() -> u64 { 15 } fn default_max_fetch_prev_events() -> u16 { 192_u16 } +fn default_max_concurrent_inbound_transactions() -> usize { 150 } + fn default_tracing_flame_filter() -> String { cfg!(debug_assertions) .then_some("trace,h2=off") diff --git a/src/service/transaction_ids/mod.rs b/src/service/transaction_ids/mod.rs index 1c78396fb..3b9a928c0 100644 --- a/src/service/transaction_ids/mod.rs +++ b/src/service/transaction_ids/mod.rs @@ -37,7 +37,7 @@ impl crate::Service for Service { }, servername_txnid_response_cache: Arc::new(SyncRwLock::new(HashMap::new())), servername_txnid_active: Arc::new(SyncRwLock::new(HashMap::new())), - max_active_txns: 50, // TODO: fetch from config + max_active_txns: args.depend::("config").max_concurrent_inbound_transactions })) }