Add default request timeout
Diff
Cargo.lock | 1 +
Cargo.toml | 2 +-
flake.nix | 7 +++++++
src/main.rs | 6 ++++++
4 files changed, 13 insertions(+), 3 deletions(-)
@@ -2802,6 +2802,7 @@
"http-body 1.0.0",
"http-body-util",
"pin-project-lite",
"tokio",
"tower-layer",
"tower-service",
]
@@ -45,7 +45,7 @@
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"
@@ -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";
@@ -34,7 +34,7 @@
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 @@
#[clap(long, default_value_t = RefreshInterval::Duration(Duration::from_secs(300)))]
refresh_interval: RefreshInterval,
#[clap(long, default_value_t = Duration::from_secs(10).into())]
request_timeout: humantime::Duration,
}
#[derive(Debug, Clone, Copy)]
@@ -204,6 +207,7 @@
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))