Skip to content

Commit

Permalink
[Hotfix] Extend solver engine request body limit (#2223)
Browse files Browse the repository at this point in the history
# Description
We are seeing 413 repsonses between the driver and solver engine in
prod. Default limit seems to be 2MB
([docs](https://docs.rs/axum/latest/axum/extract/struct.DefaultBodyLimit.html))

# Changes
- [x] Explicitly set the limit larger (10MB)
- [x] Disable default body limit in axum

## How to test
No longer see 413 errors in shadow

Locally override autopilot to send a sovle request with 3x the orders.
No longer see 413s.
  • Loading branch information
fleupold authored and mfw78 committed Dec 29, 2023
1 parent d8ab692 commit 36001d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion crates/driver/src/infra/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl Api {
})));
let path = format!("/{name}");
infra::observe::mounting_solver(&name, &path);
app = app.nest(&path, router);
app = app
.nest(&path, router)
.layer(axum::extract::DefaultBodyLimit::disable());
}

let make_svc = observe::make_service_with_task_local_storage!(app);
Expand Down
8 changes: 7 additions & 1 deletion crates/solvers/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use {

mod routes;

const REQUEST_BODY_LIMIT: usize = 10 * 1024 * 1024;

pub struct Api {
pub addr: SocketAddr,
pub solver: Solver,
Expand All @@ -20,14 +22,18 @@ impl Api {
shutdown: impl Future<Output = ()> + Send + 'static,
) -> Result<(), hyper::Error> {
let app = axum::Router::new()
.layer(tower::ServiceBuilder::new().layer(
tower_http::limit::RequestBodyLimitLayer::new(REQUEST_BODY_LIMIT),
))
.route("/metrics", axum::routing::get(routes::metrics))
.route("/healthz", axum::routing::get(routes::healthz))
.route("/solve", axum::routing::post(routes::solve))
.route("/notify", axum::routing::post(routes::notify))
.layer(
tower::ServiceBuilder::new().layer(tower_http::trace::TraceLayer::new_for_http()),
)
.with_state(Arc::new(self.solver));
.with_state(Arc::new(self.solver))
.layer(axum::extract::DefaultBodyLimit::disable());

let make_svc = observe::make_service_with_task_local_storage!(app);

Expand Down

0 comments on commit 36001d0

Please sign in to comment.