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

outgoing-body flush behaviour states #80

Open
guybedford opened this issue Nov 23, 2023 · 3 comments
Open

outgoing-body flush behaviour states #80

guybedford opened this issue Nov 23, 2023 · 3 comments

Comments

@guybedford
Copy link
Contributor

guybedford commented Nov 23, 2023

As far as I can tell, outgoing-body's stream can exist in two different states:

  1. unattached to the http request, before the request is made - all writes buffer, and flush is effectively a no-op.
  2. attached to the outgoing http request after it has been made - in this state, flush functions correctly.

In state (1), does the subscribe just fail if we exceed the high watermark? Or is the high watermark functionality also disabled?

Effectively, does that mean that a transition from state (1) to state (2) change it from permitting writes over the high watermark to not?

@guybedford
Copy link
Contributor Author

The specific issue I hit here was that blocking-write-and-flush wasn't functioning correctly in this implementation due to the stream being unflushable before it has been attached to the http request.

@pchickey
Copy link
Contributor

pchickey commented Nov 27, 2023

Just discussed this with @elliottt -

In case 1, we don't want to change the meaning of flush to mean nothing. Instead, calling flush should make the body stream not ready for writing until the request is sent successfully. A call to blocking-flush or blocking-write-and-flush would block forever, so in that case implementations should trap. (This is a particular special case where the wasi-http state of the body, as well as the state of the stream, would be required to determine that the implementation should trap, so we won't require it outright because that might be too difficult to implement in some cases - instead, those calls can hang forever, which is also correct but a worse DX.)

One valid implementation of the body stream is permitting no buffering at all, so in state 1 it would never be write ready, and in state 2 it would only become write ready for whatever the underlying network layer buffers. That isn't a very realistic implementation, though, so we expect most implementations will permit some amount of buffering in both states 1 and 2, where once that buffering is full check-write returns 0 until the buffer is emptied. In state 1, either filling the buffer or calling flush will make the check-write return 0 until the body is sent and emptied, and in state 2 it would still need the network layer to empty it.

@guybedford
Copy link
Contributor Author

This sounds like a sensible direction and the right set of tradeoffs to make to me.

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

No branches or pull requests

2 participants