about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-08 12:38:02 +0000
committerPjotr <wrk@bosa.lan>2026-11-08 12:38:02 +0000
commitb8fdbb3d60603c07cacf9f406ed1a5c228223829 (patch)
tree10fe8f955bf4ce40b4317b030a999d4f80736e7a /src
parentc008bdeca126062b2ab87bb82e7fc9ae05060e5f (diff)
downloadgenenetwork4-b8fdbb3d60603c07cacf9f406ed1a5c228223829.tar.gz
http: accept bodies up to 64 MiB, not axum's 2 MiB default
A caller posting a mapping result back to /plot/rqtl -- or a compute
request carrying a value per individual plus covariates -- was refused
with `413 Failed to buffer the request body: length limit exceeded`. That
is axum's DefaultBodyLimit, 2 MiB, which nothing here had raised: a real
GEMMA run on the BXD WGS panel is ~1.9 MB, so the plot endpoints sat just
under the cap and anything bigger (a genome-sized run, or every animal's
covariate value) fell over it. nginx's 10m was never the binding limit.

* src/lib.rs (BODY_LIMIT_BYTES): 64 MiB, with the reasoning and the note
that a proxy has to allow as much or it refuses first.
* etc/nginx-vesuvio.pu.ac.ke.conf, docs/nginx.md: client_max_body_size
64m, so the two limits agree instead of the proxy cutting in at 10m.
* README.md ("Request body size"): both caps, and that a request does not
need to be large -- `{"case_attribute": "Sex"}` has the server read the
attribute and align it, where posting a value per animal is pure payload.

Verified: the 11.9 MB body that was refused now returns an SVG; 67 MB
still gets axum's 413.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c3efcca..3ccc12f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -106,6 +106,16 @@ pub fn app() -> Router {
     let (router, api) = api_router.split_for_parts();
     router
         .route("/openapi.json", axum::routing::get(|| async { Json(api) }))
+        // axum's default is 2 MB, which a request legitimately exceeds:
+        // /plot/* takes a whole mapping response back (a real GEMMA run
+        // on the BXD WGS panel is ~1.9 MB, and a genome-sized run is
+        // tens of MB), and /compute/* carries one value per individual
+        // plus up to eight covariates. A body over the limit is refused
+        // with axum's own plain-text 413 before any handler sees it, so
+        // the limit has to sit above what the API accepts. nginx's
+        // client_max_body_size must be at least as large (64m in
+        // etc/nginx-vesuvio.pu.ac.ke.conf), or it refuses first.
+        .layer(axum::extract::DefaultBodyLimit::max(BODY_LIMIT_BYTES))
         // Assigns each request an x-request-id (if the client didn't
         // already send one) and copies it onto the response, so it can be
         // included in ApiError bodies (see error.rs) and correlated
@@ -114,6 +124,12 @@ pub fn app() -> Router {
         .layer(SetRequestIdLayer::x_request_id(MakeRequestUuid))
 }
 
+/// The largest request body the API accepts: 64 MiB, comfortably above a
+/// whole mapping result posted back to /plot/* and above a panel's worth
+/// of samples plus covariates, and still small enough that a mistake
+/// cannot exhaust memory.
+const BODY_LIMIT_BYTES: usize = 64 * 1024 * 1024;
+
 // hello_world and version predate the domain-module split and don't
 // belong to a data domain; kept here as top-level utility routes.
 // hello_world (a plain-text liveness greeting) is the one handler