diff --git a/Cargo.lock b/Cargo.lock
@@ -2802,6 +2802,7 @@ dependencies = [
"http-body 1.0.0",
"http-body-util",
"pin-project-lite",
+ "tokio",
"tower-layer",
"tower-service",
]
diff --git a/Cargo.toml b/Cargo.toml
@@ -45,7 +45,7 @@ tokio-stream = "0.1"
tower = "0.4"
tower-service = "0.3"
tower-layer = "0.3"
-tower-http = { version = "0.5", features = ["cors"] }
+tower-http = { version = "0.5", features = ["cors", "timeout"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
unix_mode = "0.1"
diff --git a/flake.nix b/flake.nix
@@ -47,6 +47,11 @@
description = "Path to repositories";
type = types.path;
};
+ requestTimeout = mkOption {
+ default = "10s";
+ description = "Timeout for incoming HTTP requests";
+ type = types.str;
+ };
};
config = mkIf cfg.enable {
@@ -65,7 +70,7 @@
path = [ pkgs.git ];
serviceConfig = {
Type = "exec";
- ExecStart = "${self.defaultPackage."${system}"}/bin/rgit --db-store ${cfg.dbStorePath} ${cfg.bindAddress} ${cfg.repositoryStorePath}";
+ ExecStart = "${self.defaultPackage."${system}"}/bin/rgit --request-timeout ${cfg.requestTimeout} --db-store ${cfg.dbStorePath} ${cfg.bindAddress} ${cfg.repositoryStorePath}";
Restart = "on-failure";
User = "rgit";
diff --git a/src/main.rs b/src/main.rs
@@ -34,7 +34,7 @@ use tokio::{
signal::unix::{signal, SignalKind},
sync::mpsc,
};
-use tower_http::cors::CorsLayer;
+use tower_http::{cors::CorsLayer, timeout::TimeoutLayer};
use tower_layer::layer_fn;
use tracing::{error, info, instrument, warn};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
@@ -76,6 +76,9 @@ pub struct Args {
/// Configures the metadata refresh interval (eg. "never" or "60s")
#[clap(long, default_value_t = RefreshInterval::Duration(Duration::from_secs(300)))]
refresh_interval: RefreshInterval,
+ /// Configures the request timeout.
+ #[clap(long, default_value_t = Duration::from_secs(10).into())]
+ request_timeout: humantime::Duration,
}
#[derive(Debug, Clone, Copy)]
@@ -204,6 +207,7 @@ async fn main() -> Result<(), anyhow::Error> {
get(static_favicon(include_bytes!("../statics/favicon.ico"))),
)
.fallback(methods::repo::service)
+ .layer(TimeoutLayer::new(args.request_timeout.into()))
.layer(layer_fn(LoggingMiddleware))
.layer(Extension(Arc::new(Git::new(syntax_set))))
.layer(Extension(db))