-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor: allow Subscribe::ready
to be fallible
#7713
base: main
Are you sure you want to change the base?
Conversation
e646da0
to
d8dfec4
Compare
d8dfec4
to
2a6d4f4
Compare
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
2a6d4f4
to
fd63bc5
Compare
Could you describe a bit more when an embedder might want to return a trap via this method? I agree the current interface doesn't allow it, but one reason we chose to not do this is to avoid a common mistake of performing I/O and returning the error in the |
First I'll comment on this part:
This may not be possible in a generic case, because for this to work the host would need to know which accessor is coupled with the pollable and this relationship is not in any way encoded in WIT. In other words, the host must be aware of the executed Wasm component runtime behavior/logic in order to expose the error in the accessor. Consider resource future-trailers {
subscribe: func() -> pollable;
get: func() -> option<result<result<option<trailers>, error-code>>>;
} Because the host at compile time is aware of the behavior of But in case of some generic resource, which is only known at runtime, e.g.: resource custom-trailers {
subscribe-one: func() -> pollable;
subscribe-two: func() -> pollable;
get: func() -> option<result<result<option<trailers>, error-code>>>;
foo: func() -> string;
} The host may not in any way know how to communicate the error (and which one) to the guest. The interface, may, in fact, not even utilize an accessor and simply rely on the fact that the Coming back to the first part: My exact use case is a "pollable", which is a remote entity accessible via network:
If network connection in 1. fails, it can just be retried, perhaps with backoff - that part works well with existing API. |
Ok makes sense, thanks for explaining. Can this be fixed though by updating the WIT-level APIs? For example in your In your use case of a remote-owned resource, this is something that I'd at least personally expect to go through an error somewhere in the WIT. One option would be that when the pollable says "ready" any future operations on it trap (communicating the fatal error) or by updating the APIs there to surface an error instead. |
In the current implementation
Subscribe::ready
is assumed to be infallible, which does not work in a generic case, where the implementation may require, in fact, to cause a trap in the guest.This is important, because implementations that require ability to trap in host
wasi::io::poll/pollable
would otherwise require to implement their ownwasi::io::poll/pollable
, meaning that they would not be able to reuse all the existing WASI crate implementations (https://docs.rs/wasmtime-wasi/latest/wasmtime_wasi/preview2/trait.Subscribe.html#implementors), potentially locking developers out of most of WASI functionality (due to thePollable
concrete type being used in signatures, which cannot be externally constructed)