Skip to content

Commit 7714bdb

Browse files
committed
fix(network): answer a JSON-RPC or GraphQL request timeout with 408
These paths read the whole body before middleware runs, so a request timeout should not occur. If it does, send the same 408 request_timeout as the REST path instead of failing the relay with a generic error. Signed-off-by: Piotr Mlocek <[email protected]>
1 parent 702284c commit 7714bdb

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

  • crates/openshell-supervisor-network/src/l7

‎crates/openshell-supervisor-network/src/l7/relay.rs‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,11 +2809,23 @@ where
28092809
.await?;
28102810
let req = match middleware_result {
28112811
MiddlewareApplyResult::Allowed(request) => request,
2812-
MiddlewareApplyResult::Streamed { .. } | MiddlewareApplyResult::RequestTimeout => {
2812+
MiddlewareApplyResult::Streamed { .. } => {
28132813
return Err(miette!(
28142814
"body-aware request middleware must collect the request body"
28152815
));
28162816
}
2817+
// The body was read before middleware ran, so the client
2818+
// cannot stall it; answer like the REST path if it happens.
2819+
MiddlewareApplyResult::RequestTimeout => {
2820+
crate::l7::middleware::send_request_timeout_response(
2821+
&request_info.action,
2822+
client,
2823+
ctx,
2824+
&redacted_target,
2825+
)
2826+
.await?;
2827+
return Ok(());
2828+
}
28172829
MiddlewareApplyResult::Denied { denial, failure } => {
28182830
if let Some(observer) = observer.as_ref() {
28192831
observer.observe(EndpointResult::PolicyDenied);
@@ -3098,11 +3110,23 @@ where
30983110
.await?;
30993111
let req = match middleware_result {
31003112
MiddlewareApplyResult::Allowed(request) => request,
3101-
MiddlewareApplyResult::Streamed { .. } | MiddlewareApplyResult::RequestTimeout => {
3113+
MiddlewareApplyResult::Streamed { .. } => {
31023114
return Err(miette!(
31033115
"body-aware request middleware must collect the request body"
31043116
));
31053117
}
3118+
// The body was read before middleware ran, so the client
3119+
// cannot stall it; answer like the REST path if it happens.
3120+
MiddlewareApplyResult::RequestTimeout => {
3121+
crate::l7::middleware::send_request_timeout_response(
3122+
&request_info.action,
3123+
client,
3124+
ctx,
3125+
&redacted_target,
3126+
)
3127+
.await?;
3128+
return Ok(());
3129+
}
31063130
MiddlewareApplyResult::Denied { denial, failure } => {
31073131
let denied_request = crate::l7::provider::L7Request {
31083132
action: request_info.action.clone(),

0 commit comments

Comments
 (0)