Closed
Description
Hi,
Currently it's not possible to issue another http call from Context::on_http_call_response
. Is this intentional ? If it is how is one supposed to make several http calls, for example fetch an oauth token, call another service with it, then resume the request ?
The error is:
[2020-10-25 11:04:04.792][12][critical][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1018] wasm log: panicked at 'already borrowed: BorrowMutError', /Users/svetlin/.cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/proxy-wasm-0.1.2/src/dispatcher.rs:137:14
I believe the error is caused because the dispatcher tries to borrow the callouts for a second time when registering the second http call.
The first borrow occurs when calling the on_http_call_response callback. The duration of the borrow lasts for the whole if let Some()
body.
Given that the context_id is Copy
, this method can be modified like that:
{
let context_id = match self.callouts.borrow_mut().remove(&token_id) {
Some(id) => id,
None => panic!("invalid token_id")
};
if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
self.active_id.set(context_id);
hostcalls::set_effective_context(context_id).unwrap();
http_stream.on_http_call_response(token_id, num_headers, body_size, num_trailers)
} else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) {
self.active_id.set(context_id);
hostcalls::set_effective_context(context_id).unwrap();
stream.on_http_call_response(token_id, num_headers, body_size, num_trailers)
} else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) {
self.active_id.set(context_id);
hostcalls::set_effective_context(context_id).unwrap();
root.on_http_call_response(token_id, num_headers, body_size, num_trailers)
}
}
Thus eliminating the borrow on the callouts
member, which resolves the issue.
What do you think ?
Metadata
Metadata
Assignees
Labels
No labels
Activity
SvetlinZarev commentedon Nov 9, 2020
Reproducible example:
Cargo.toml:
lib.rs:
envoy config:
Make an http request to the proxy:
As a result envoy crashes due to multiple mutable borrows:
PiotrSikora commentedon Nov 14, 2020
Thanks for the report and reproducer! I think your patch is correct. Could you send a PR?
PiotrSikora commentedon Nov 19, 2020
Hi @SvetlinZarev, I see that you pushed fix to your fork (https://github.com/SvetlinZarev/proxy-wasm-rust-sdk/commit/5190a0437c9c96ec378839598793ea98fc6769e8), but you didn't open a PR. Could you do that or are you still working on it?
SvetlinZarev commentedon Nov 19, 2020
Unfortunately I'm struggling with the OSS process at my place :( (due to the required CLA).
PiotrSikora commentedon Nov 19, 2020
Do you have any ETA or is that unlikely to happen at all?
Deletes unimplemented vNEXT doc. (proxy-wasm#40)