Skip to content

Commit a64bb1c

Browse files
committed
add test to show the issue
1 parent d03d545 commit a64bb1c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

bottlecap/src/lifecycle/listener.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ mod tests {
281281
use http_body_util::BodyExt;
282282
use tower::ServiceExt;
283283

284+
use crate::http::extract_request_body;
285+
284286
/// Builds a minimal router that applies only the body limit layer.
285287
/// The handler reads the full body (via the `Bytes` extractor), which
286288
/// is what triggers `DefaultBodyLimit` enforcement.
@@ -398,4 +400,47 @@ mod tests {
398400
"Should extract request_id from LWA proxy header"
399401
);
400402
}
403+
404+
/// Shows that `extract_request_body` fails on an oversized payload when
405+
/// behind `DefaultBodyLimit`. In `handle_end_invocation`, this failure
406+
/// causes the spawned task to early-return, silently skipping
407+
/// `universal_instrumentation_end` (trace context, span finalization,
408+
/// and status code extraction are all dropped).
409+
#[tokio::test]
410+
async fn test_extract_request_body_fails_on_oversized_payload() {
411+
// Build a router whose handler calls extract_request_body — the
412+
// same code path used inside handle_end_invocation's spawned task.
413+
async fn handler(request: axum::extract::Request) -> StatusCode {
414+
match extract_request_body(request).await {
415+
Ok(_) => StatusCode::OK,
416+
Err(_) => StatusCode::INTERNAL_SERVER_ERROR,
417+
}
418+
}
419+
420+
let router = Router::new()
421+
.route(END_INVOCATION_PATH, post(handler))
422+
.layer(DefaultBodyLimit::max(LAMBDA_INVOCATION_MAX_PAYLOAD));
423+
424+
// 6 MB + 1 byte: exceeds the DefaultBodyLimit
425+
let payload = vec![b'x'; LAMBDA_INVOCATION_MAX_PAYLOAD + 1];
426+
let req = Request::builder()
427+
.method("POST")
428+
.uri(END_INVOCATION_PATH)
429+
.header("Content-Type", "application/json")
430+
.body(Body::from(payload))
431+
.expect("failed to build request");
432+
433+
let response = router.oneshot(req).await.expect("request failed");
434+
435+
// BUG: extract_request_body fails with "length limit exceeded",
436+
// which in handle_end_invocation causes the spawned task to
437+
// early-return — universal_instrumentation_end is never called.
438+
assert_eq!(
439+
response.status(),
440+
StatusCode::INTERNAL_SERVER_ERROR,
441+
"extract_request_body should fail on oversized payload, \
442+
proving the spawned task in handle_end_invocation would \
443+
early-return and skip processing"
444+
);
445+
}
401446
}

0 commit comments

Comments
 (0)