Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use case that is not working - http_dispatch_call in on_http_response_body and on_http_call_response_body want to update response body #156

Open
joseret opened this issue Jun 10, 2022 · 12 comments

Comments

@joseret
Copy link

joseret commented Jun 10, 2022

Logic is working and using shared data to store intermediate results from http_dispatch_call to on_http_call_response_body, but when I try to replace the response_body. No method is working, generates a panic.

tried combinations of these

             // self.set_http_response_body(0, json_bytes.len(), v);
              // self.send_http_response(201, vec![], Some(json_bytes_au8));
              // wasm::types::Action::Continue;
              self.resume_http_response();

It there something I am missing. probably best is if you can help on the right calls to update the response body and then finish during the fn on_http_call_response(&mut self,

@joseret
Copy link
Author

joseret commented Jun 20, 2022

ping. Anyone have some thoughts on this?

@zendesk-fcamenfo
Copy link

The flow that works for me is something like this:

  • on_http_request_body() -> perform http_dispatch_call, return Action::Pause
  • on_http_call_response() -> receive result from HTTP call, modify body with set_http_response_body() and then call resume_http_resposne()

@joseret
Copy link
Author

joseret commented Jun 21, 2022

Thanks! Yes, that works for me too. But I need the initial on_http_response_body to retrieve some information used on the dispatch call and that is where I am stuck and it would seem that proxy is in a state that cannot change the body, since I got to on_http_response_body complete data

@zendesk-fcamenfo
Copy link

zendesk-fcamenfo commented Jun 22, 2022

Not sure I understand what the problem is. This flow works on my end:

  • Retrieve data from the body when in on_http_request_body, then use it on an HTTP dispatch call.
    • Return Action::Pause so the body is still buffered and can be changed
  • Modify the body when in on_http_call_response, which would happen after on_http_request_body has completed. Then resume sending upstream with resume_http_response()

Are you getting some error?

@joseret
Copy link
Author

joseret commented Jun 22, 2022

I am issuing thee HTTP dispatch in the on_http_response_body (not in the on_http_request_body so how do I receive the response_body, then do dispatch, and from on_response_call_body modify the response_body going to requestor. Hopefully tha tshows thee difference. Two difference sequences in two different states. I will attach the envoy trace and see if that helps clarify but seems to be we can't buffeer on_http_response and then change it (or can we?)

@zendesk-fcamenfo
Copy link

zendesk-fcamenfo commented Jun 22, 2022

Just tried and it works with my codebase (uses GRPC instead of HTTP but should work the same). Version 0.1.4 of proxy-wasm.

  1. on_http_response_body() -> wait until _end_of_stream = true, then perform dispatch_grpc_call(), then return Action::Pause
  2. on_grpc_call_response() -> perform set_http_response_body(), then call resume_http_response()

And I can see the modified body being returned to a curl command.

One other thing, have you removed the content-length header before modifying the body?

@joseret
Copy link
Author

joseret commented Jun 22, 2022 via email

@joseret
Copy link
Author

joseret commented Jun 22, 2022

Great to hear. I thought I remove content header on the response_header but will make suree

@zendesk-fcamenfo
Copy link

Also make sure you are setting the start and size parameters correctly in set_http_response_body

If I remember correctly, a (size < new body size) will perform a prepend operation on the body

@joseret
Copy link
Author

joseret commented Jun 22, 2022

This is similar error, there is no content-length header, so set_request_headers fail

[2022-06-22 22:52:17.219][516433][critical][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1227] wasm log my_plugin my_root_id my_vm_id: panicked at 'unexpected status: 2', /home/jr/.cargo/registry/src/github.com-1ecc6299db9ec823/proxy-wasm-0.1.4/src/hostcalls.rs:211:23
[2022-06-22 22:52:17.219][516433][error][wasm] [external/envoy/source/extensions/common/wasm/wasm_vm.cc:39] Function: proxy_on_http_call_response failed: Uncaught RuntimeError: unreachable
Proxy-Wasm plugin in-VM backtrace:
0: 0x32809 - __rust_start_panic
1: 0x3231e - rust_panic
2: 0x322ee - _ZN3std9panicking20rust_panic_with_hook17h623ac32ff431b114E
3: 0x31926 - ZN3std9panicking19begin_panic_handler28$u7b$$u7b$closure$u7d$$u7d$17h4939ceabc7a11060E
4: 0x31865 - _ZN3std10sys_common9backtrace26__rust_end_short_backtrace17h9f6add6df687a1bfE
5: 0x31f60 - rust_begin_unwind
6: 0x3948d - _ZN4core9panicking9panic_fmt17h5118e89563022e7eE
7: 0x213be - _ZN10proxy_wasm9hostcalls7set_map17h8814604a6362fcdfE
8: 0x477f - ZN96$LT$rust_filter_poc_v1..FilterApplicationHttpHandler$u20$as$u20$proxy_wasm..traits..Context$GT$21on_http_call_response17h27af8f70079c8cd4E
9: 0x1d235 - _ZN10proxy_wasm10dispatcher10Dispatcher21on_http_call_response17h12866b54eb9eea98E

@joseret
Copy link
Author

joseret commented Jun 22, 2022

error.log
Here is the trace

@zendesk-fcamenfo
Copy link

zendesk-fcamenfo commented Jun 23, 2022

Yes, that's a different case than the body. When you're at or past the on_http_request/response_body callbacks, the HTTP headers have already been forwarded up or downstream. It's not allowed to buffer the headers along with the body. So no header modification is possible at that stage.

I've been hit by the same problem, you can only modify headers when in the on_http_request/response_headers callback.

I think this is related: proxy-wasm/proxy-wasm-cpp-host#143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants