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

Turn request-options into a resource #7417

Merged

Conversation

elliottt
Copy link
Member

@elliottt elliottt commented Oct 30, 2023

As we'd like to be able to modify request-options in the future without breaking compatibility with older guests, turn request-options into a resource. This allows us to expose getters and setters instead of fields on a record, which gives the embedder flexibility in what additional options are allowed.

Fixes #7409

@elliottt elliottt requested a review from a team as a code owner October 30, 2023 21:39
@elliottt elliottt requested review from alexcrichton and pchickey and removed request for a team October 30, 2023 21:39
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Random drive-by thought unrelated to this change specifically, could the *-ms bits be updated to take the duration type in #7358 which would give more precision here as well?

crates/wasi-http/wit/deps/http/types.wit Outdated Show resolved Hide resolved
@@ -257,6 +257,13 @@ pub struct HostOutgoingRequest {
pub body: Option<HyperOutgoingBody>,
}

#[derive(Default)]
pub struct HostRequestOptions {
pub connect_timeout: Option<u32>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets use either std or tokio::time::Duration to represent these values in the host as early as we can.

Copy link
Member Author

Choose a reason for hiding this comment

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

The downside is that the getters become quite fallible as they're turning a std::time::Duration back into a u32.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isnt that resolved when we switch to using a monotonic duration, which is a u64?

Copy link
Member Author

Choose a reason for hiding this comment

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

std::time::Duration::as_millis returns a u128, so we won't avoid it completely.

Copy link
Member Author

Choose a reason for hiding this comment

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

I implemented this by treating conversion failure from u128 as an Ok(None) return value. Since we default all these timeouts to None anyway, I think a conversion failure would mean that the guest somehow managed to set a larger than u32 value to begin with, then tried to get one back. The host setting an invalid default would be the other possibility, but we don't do this anywhere in wasmtime currently.

@pchickey
Copy link
Contributor

Random drive-by thought unrelated to this change specifically, could the *-ms bits be updated to take the duration type in #7358 which would give more precision here as well?

Yes, we can make that change as soon as 7358 lands.

@github-actions github-actions bot added the wasi Issues pertaining to WASI label Oct 30, 2023
@pchickey
Copy link
Contributor

You can merge with main and adopt duration now!

@elliottt elliottt force-pushed the trevor/request-options-resource branch from e6e46b9 to 711e1f4 Compare October 30, 2023 23:40
@elliottt elliottt added this pull request to the merge queue Oct 31, 2023
Merged via the queue into bytecodealliance:main with commit 2f83f97 Oct 31, 2023
18 checks passed
@elliottt elliottt deleted the trevor/request-options-resource branch October 31, 2023 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wasi-http: make request-options into a resource
3 participants