Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout handling of incoming requests after 25 seconds #222

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ In Devlopment
- Serve a `/robots.txt` file denying all robots
- Log `User-Agent` and `X-Request-ID` headers
- Rate limit incoming requests
- Handling of incoming requests now times out after 25 seconds

v0.5.0 (2024-11-18)
-------------------
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ thiserror = "2.0.11"
time = { version = "0.3.37", features = ["formatting", "macros", "parsing", "serde"] }
tokio = { version = "1.43.0", features = ["macros", "net", "rt-multi-thread", "time"] }
tower = { version = "0.5.2", features = ["util"] }
tower-http = { version = "0.6.2", features = ["set-header", "trace"] }
tower-http = { version = "0.6.2", features = ["set-header", "timeout", "trace"] }
tower_governor = { version = "0.6.0", features = ["tracing"] }
tracing = "0.1.41"
tracing-subscriber = { version = "0.3.19", features = ["json", "local-time", "time"] }
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ use tower::service_fn;
use tower_governor::{
governor::GovernorConfigBuilder, key_extractor::SmartIpKeyExtractor, GovernorLayer,
};
use tower_http::{set_header::response::SetResponseHeaderLayer, trace::TraceLayer};
use tower_http::{
set_header::response::SetResponseHeaderLayer, timeout::TimeoutLayer, trace::TraceLayer,
};
use tracing::Level;
use tracing_subscriber::{filter::Targets, fmt::time::OffsetTime, prelude::*};

Expand Down Expand Up @@ -184,6 +186,7 @@ fn get_app(cfg: Config) -> anyhow::Result<Router> {
ACCESS_CONTROL_ALLOW_ORIGIN,
HeaderValue::from_static("*"),
))
.layer(TimeoutLayer::new(std::time::Duration::from_secs(25)))
.layer(GovernorLayer {
config: Arc::new(
GovernorConfigBuilder::default()
Expand Down
Loading