-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
If a command output writer writes 4096 bytes before it completed reading it's input, it won't be able to read the rest when using the HTTP API #3367
Comments
What I already tried is that I wrapped the http |
That is a major flow as it prevents us from streaming the input and the output. Is there any solutions for that or is it limitation of http protocol? |
AFAIK this is a limitation of the HTTP protocol. From the HTTP point of view this makes sense as you won't be able to tell whether a request is valid or not if you didn't read it completely. |
So does this mean that a sufficiently large ipfs add would break? |
Actually, how does |
Hmm, it seems to work with |
Okay, I think I got it. It is okay to read after writing or flushing if you use multipart requests and call |
@keks Ah, okay. So we should do some special handling there, and make it clear that you should use multipart if you intend on being in that scenario. |
re #3304 (comment):
Hmm, I never wrote an ipfs command and I'm not sure how often this will be done. I propose adding a source code comment attached to the |
I stumbled upon this when researching #3336.
When the HTTP API receives a request, it starts the command using the HTTP arguments as arguments to the commands and feeds the request body to the command "as stdin". The command also has an stdout, which is an
io. Reader
on the caller's side.When you write to an
http.ResponseWriter
, all unconsumed data in the request body is lost.To send the command result to the client,
flushCopy
is called withr
being the command output andw
being thehttp.ResponseWriter
.At the end of the first iteration, the connection is being flushed and the response headers are sent. If the request has not been fully consumed until then, it will be truncated.
The problem is that the information whether the input has been consumed is not available inside
flushCopy
, so to fix this we need to find a way do pass it.The reason I think this is important is that at the moment when you subscribe a pubsub topic they headers are not being sent until that
Flush()
after the read is called. This way the all Go clients will block when sending their request, because they wait for the headers.That is also the reason I added a
Flush
at the loop top in the first place. I wasn't aware that you couldn't read the body afterwards.The text was updated successfully, but these errors were encountered: