-
Notifications
You must be signed in to change notification settings - Fork 20
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
Proposal: add output-stream::(blocking-)close
#86
base: main
Are you sure you want to change the base?
Conversation
If I understand this correctly, this would add an effective requirement for consumers of APIs that have For example, the Besides compatibility with Preview 2 APIs, there's also the question of how this could be implemented. No major programming language today expects users to do the equivalent of calling |
I conceptualize
In the case of |
I'm concerned about |
I'd say: Discard it. (*) = Actually, POSIX' |
The fact that many applications ignore errors from |
From talking with @lukewagner about Preview 3, it's likely that Preview 3 streams won't have an equivalent of a fallible As background, the idea for Preview 3 streams is that there won't be a separate input-stream and output-stream that can't be directly composed with each other. There's just a Pure stream transfomers could have a signture like That's quite different than the simple resource-based |
After discussing this further in person, my current understanding is that with Preview 3 streams:
Mapping this back to Preview 2 streams: input-stream
In terms of WIT, a P2 signature of: receive: func() -> input-stream; can be trivially converted to P3 like so: receive: func() -> stream<u8, error>;
|
Today, there is no generic way to gracefully close a stream, other than to
drop
it and hope for the best.Wasi-sockets already has an ad-hoc workaround in the form of
tcp-socket::shutdown(send)
. Similarly (but not exactly the same), wasi-http hasoutgoing-body::finish
.I'm currently sketching out a TLS interface for WASI, where the TLS client/server does not perform any I/O on its own but instead acts as a stream transformer: cleartext data goes in, TLS data comes out, and vice versa. The stream transformer should not have to know where its inputs & outputs come from and go to. One thing that differentiates TLS from plain TCP is that a graceful shutdown requires additional I/O (a "close_notify" message to be sent).
One way to go about this is to add yet another set of bespoke methods on the TLS client/server resource type to close the output streams.
But preferably the end-of-stream indication should be propagated automagically.
I propose to add the ability to explicitly shut down a writable stream, asynchronously. This is not too far off from how existing programming environments work:
futures::io::AsyncWrite::poll_close
tokio::io::AsyncWrite::poll_shutdown
System.IO.Stream.DisposeAsync
stream.Writable.end
asyncDispose
(stage 3 proposal)asyncio.StreamWriter.close + wait_close