-
Notifications
You must be signed in to change notification settings - Fork 43
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
"Continue" response can interleave with response data #176
Comments
Could you include an example of code that does this? I'm curious how you're writing a response before reading from the body |
I don't have an example to hand, but I can produce one if that would help. I believe it should be fairly easy to reproduce:
The server code will begin by encoding the response headers into the stream, and will then begin reading from the body. This will in turn trigger a read from the request body (since they are one and the same) which will result in the |
It seems the ordering might have been messed up here a bit. The design was intended so that the moment we start to read the request body, we write out But you're right to point out that if we start writing to the response stream, then read the body, |
Won't this result in the FWIW, I have an experimental branch which solves several of these related issues (and fixes pipelining), I'll open a draft PR with that soon (there's one test failing right now). |
Oh, I was thinking this would be done through two atomic bools (or equivalent).
Ohhh, neat! |
Sorry I didn't mean always sent, rather, even if the "Expect" header is sent, there is an optimization that if the body is never read, we don't send the continue message at all. If we send the continue message on the first write, then that optimization won't ever kick in. In my branch, I prevent this by having further writes to the stream block until a decision has been made about whether to send the "100 Continue" or not (if you drop the Body without reading it, then it will not send it, if you start reading from it, it will send it). However, this only an improvement: misuse (by attempting to write before doing either of those things) will result in a deadlock rather than a corrupted response, One possible solution other than those listed above would be to transparently buffer the writes in memory until the request body is either read or dropped. I'm leaning towards this one right now. |
This seems to be caused by the |
Example:
There are few possible solutions:
Make it an error to read from the request body after starting to write a response. This is not great because eg. an echo server might want to stream data back without buffering it in memory.
Send "100 Continue" before either a read from the request body, or when starting to write the response. Only omit it if the server explicitly drops the request body before beginning to send a response.
Some other way of having the server make an explicit choice of whether the client should continue sending the body.
The text was updated successfully, but these errors were encountered: