-
Notifications
You must be signed in to change notification settings - Fork 95
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
Support invoking wasi:http/incoming-handler #1249
Conversation
@@ -16,24 +16,24 @@ use golem_wasm_ast::analysis::{AnalysedExport, AnalysedFunction, AnalysedInstanc | |||
|
|||
use rib::{ParsedFunctionName, ParsedFunctionReference, ParsedFunctionSite}; | |||
|
|||
pub trait AnalysedExportExtensions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
9541bf7
to
bfd6632
Compare
bfd6632
to
e99b2d1
Compare
golem-worker-executor-base/src/virtual_export_compat/http_incoming_handler.rs
Show resolved
Hide resolved
.new_response_outparam(sender) | ||
.unwrap(); | ||
|
||
unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out from reading it the need of unsafe here. Would you mind explaining it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comes from the async_scoped crate. https://docs.rs/async-scoped/latest/async_scoped/
The invariant they want here is just that:
An asynchronous function that creates a scope and immediately awaits the stream. The outputs of the futures are collected as a Vec and returned along with the output of the block.
Safety
This function is not completely safe: please see cancellation_soundness in [tests.rs](https://github.com/rmanoka/async-scoped/blob/master/src/tests.rs) for a test-case that suggests how this can lead to invalid memory access if not dealt with care.
The caller must ensure that the lifetime ’a is valid until the returned future is fully driven. Dropping the future is okay, but blocks the current thread until all spawned futures complete.
Will add a comment.
Ok(HttpBodyContent(Bytes::from(result))) | ||
} | ||
|
||
pub fn to_value(self) -> Value { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of these to_value
calls consider implementing the IntoValue
type class (from wasm-rpc), that also requires you to specify the type, but it will allow us to use these in more scenarios (for example better integrating it PublicOplogEntry
etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annoyance here is that only one half of the types here need to go to values (the other half is being converted from values), while we need to have the type for all of them.
This would suggest that we need a counterpart of IntoValue that can go from values (FromValue?) and then we would likely want to split the type portions out from both.
I wanted to avoid doing this for now and just implemented the needed functionality as plain functions. We can always implement IntoValue if we end up needing it for a specific type.
|
||
let mut store_context = store.as_context_mut(); | ||
|
||
let current_fuel_level = store_context.get_fuel().unwrap_or(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These post-invocation steps are now duplicated, I guess, maybe worth extracting them to a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, factored out into a new function
@@ -73,6 +74,7 @@ pub trait WorkerCtx: | |||
+ Send | |||
+ Sync | |||
+ Sized | |||
+ DurableWorkerCtxView<Self> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary - and breaks the (now unused) purpose of this trait that it is independent of DurableWorkerCtx
(that's just one implementation - originally we had a non-durable one too).
We already have as_wasi_http_view
and as_wasi_view
below, isn't that enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, Ctx
decides whether worker context handles things related to durability. So this implies the above comment from @vigoo should be made work if it's not working now, in my view - which is simply .as_wasi_view
where ever it is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adressed
|
||
#[test] | ||
#[tracing::instrument] | ||
async fn wasi_incoming_request_handler_compat( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better test coverage please! :) (headers, body, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is coming 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
let res_or_error = match receiver.await { | ||
let out = receiver.await; | ||
|
||
tracing::warn!("received response {:?}", out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove these debug warn!s (there is another one below too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found two debug logs that should be removed, otherwise good to go!
resolves #1184