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

Support invoking wasi:http/incoming-handler #1249

Merged
merged 9 commits into from
Jan 21, 2025
Merged

Support invoking wasi:http/incoming-handler #1249

merged 9 commits into from
Jan 21, 2025

Conversation

mschuwalow
Copy link
Contributor

resolves #1184

@@ -16,24 +16,24 @@ use golem_wasm_ast::analysis::{AnalysedExport, AnalysedFunction, AnalysedInstanc

use rib::{ParsedFunctionName, ParsedFunctionReference, ParsedFunctionSite};

pub trait AnalysedExportExtensions {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were unused

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mschuwalow mschuwalow force-pushed the wasi-http-3 branch 2 times, most recently from 9541bf7 to bfd6632 Compare January 18, 2025 17:12
.new_response_outparam(sender)
.unwrap();

unsafe {
Copy link
Contributor

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?

Copy link
Contributor Author

@mschuwalow mschuwalow Jan 19, 2025

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 {
Copy link
Contributor

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)

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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>
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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(
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is coming 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mschuwalow mschuwalow requested review from vigoo and afsalthaj January 20, 2025 17:27
let res_or_error = match receiver.await {
let out = receiver.await;

tracing::warn!("received response {:?}", out);
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, sorry

Copy link
Contributor

@vigoo vigoo left a 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!

@mschuwalow mschuwalow merged commit d22a30c into main Jan 21, 2025
20 checks passed
@mschuwalow mschuwalow deleted the wasi-http-3 branch January 21, 2025 11:00
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

Successfully merging this pull request may close these issues.

Expose a new invoke function via gRPC from Worker Executor for incoming HTTP requests
3 participants