Skip to content

Commit

Permalink
Merge pull request #158 from Kuadrant/failure-mode-propagation
Browse files Browse the repository at this point in the history
Do not resume on failure
  • Loading branch information
adam-cattermole authored Dec 5, 2024
2 parents 801911b + 335f615 commit 2868f20
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

41 changes: 28 additions & 13 deletions src/filter/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ impl Filter {
}
}
}

fn process_next_op(&self) {
match self.operation_dispatcher.borrow_mut().next() {
Ok(some_op) => {
if some_op.is_none() {
// No more operations left in queue, resuming
self.resume_http_request();
}
}
Err(op_err) => {
// If desired, we could check the error status.
GrpcService::handle_error_on_grpc_response(op_err.failure_mode);
}
}
}
}

impl HttpContext for Filter {
Expand Down Expand Up @@ -134,21 +149,21 @@ impl Context for Filter {

match op_res {
Ok(operation) => {
if let Ok(result) = GrpcService::process_grpc_response(operation, resp_size) {
// add the response headers
self.response_headers_to_add.extend(result.response_headers);
// call the next op
match self.operation_dispatcher.borrow_mut().next() {
Ok(some_op) => {
if some_op.is_none() {
// No more operations left in queue, resuming
self.resume_http_request();
match GrpcService::process_grpc_response(Rc::clone(&operation), resp_size) {
Ok(result) => {
// add the response headers
self.response_headers_to_add.extend(result.response_headers);
// call the next op
self.process_next_op();
}
Err(_) => {
match operation.get_failure_mode() {
FailureMode::Deny => {}
FailureMode::Allow => {
// call the next op
self.process_next_op();
}
}
Err(op_err) => {
// If desired, we could check the error status.
GrpcService::handle_error_on_grpc_response(op_err.failure_mode);
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ impl GrpcService {
hostcalls::send_http_response(500, vec![], Some(b"Internal Server Error.\n"))
.expect("failed to send_http_response 500");
}
FailureMode::Allow => {
hostcalls::resume_http_request().expect("failed to resume_http_request")
}
FailureMode::Allow => {}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn it_auths() {
None,
Some(5000),
)
.returning(Some(42))
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Expand Down Expand Up @@ -362,7 +362,7 @@ fn it_denies() {
None,
Some(5000),
)
.returning(Some(42))
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Expand Down Expand Up @@ -563,7 +563,7 @@ fn it_does_not_fold_auth_actions() {
None,
Some(5000),
)
.returning(Some(42))
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Expand Down Expand Up @@ -661,7 +661,7 @@ fn it_does_not_fold_auth_actions() {
None,
Some(5000),
)
.returning(Some(42))
.returning(Ok(42))
.execute_and_expect(ReturnType::None)
.unwrap();

Expand Down
Loading

0 comments on commit 2868f20

Please sign in to comment.