-
-
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
Error while files.add over HTTP API (http: invalid Read on closed Body) #5168
Comments
Looks like a go bug: golang/go#15527 As far as I can tell, work around is to avoid flushing the response till we finish reading the request. |
So, I'm pretty sure that work around is incorrect (although it appears to work). However, the diagnosis is definitely correct. |
This may also explain why our progress meters are broken. It may also explain a bunch of random errors and why some people have trouble adding large datasets to go-ipfs. |
*edit: this worked because the client was sending "connection: close". |
So, I'm not sure how to work around this. We rely on being able to stream status information while processing large requests. We usually don't notice this issue because the go-ipfs CLI usually makes a single HTTP requests and sets
I get the impression it'll be a while before go fixes this bug. |
This disables keeping http connections alive in our API and Gateway servers. It "fixes" #5168 but we really don't want to do this in practice. License: MIT Signed-off-by: Steven Allen <[email protected]>
@lidel try the fix/disable-keepalives branch if you need something to work with while we try to find a better fix. |
@Stebalien thank you for looking into this. With this info I strongly suspect the bug is responsible for a bunch of random errors users of HTTP API in browser context been reporting over past two years. I was able to confirm workaround from Edited: I was too optimistic: disabling `&progress` does not work as a reliable workaround, it just changes the conditions under which issue occurs (some files started working, others stopped).
|
Beyond "not ideal", it's also not a very reliable solution. What happens if you add a |
After playing a bit with setting Linking to workarounds:
|
This PR: - provides a fix for a bug described in https://github.com/ipfs-shipyard/ipfs-companion via workaround from ipfs/kubo#5168 (comment) - **TL;DR** Browser extension is able to detect requests to `/api/v0/add` and set `Connection: close` - moves core upload logic from background page to `quick-upload` page
@Stebalien ok, this is quite serious bug: setting Are we able to introduce some sort of opt-in, header-based workaround (that could be added to js-ipfs-api to fix it for everyone), or is it too deep in the Something like:
|
Really, we probably want to just configure the API's HTTP server to always close connections. The branch I pointed you towards does this for the gateway as well but we definitely don't want that. |
these methods are added as a temporary workaround because adding an entire dir to IPFS can cause a bug: ipfs/kubo#5168 add_zipped_dir will zip a directory and upload the zipfile to IPFS get_zipped_dir will download a zipped dir and extract it into a target directory
See discussion in ipfs/kubo#5168 We cannot stream responses with keep-alives enabled. I prefer this to not be a client feature, as otherwise users might end up shooting themselves in the foot. Note, the price is a corrupted request body which gets added normally and gives wrong hashes! License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
I have spent hours today on exactly this same issue. It appears consistently but randomly (i.e. a test fails all the time, but a very similar test of in a different place works fine, and then things get fixed by just changing some code (playing with Flush())). The result for me is actually getting a corrupted request body, resulting in the multipart reader reading different data from it and adding different content (but not failing, which is very scary). And I got to the same conclusion, the workarounds are:
Alternatively, I guess the Note that for browsers, I have read that using Also, this one seems related too: golang/go#20528 |
I've hit the exact same problem from the Java http api, and got a small test to reproduce it randomly (~1 in 5 fails): https://github.com/ipfs/java-ipfs-api/blob/master/src/test/java/io/ipfs/api/AddTest.java I've got it to work 100% in Java too by adding the following header: |
That is a good news for IPFS Companion @ianopolous ! |
Workaround for 'invalid Read on closed Body' in files.add (webext in Chrome) > Chrome does allow setting `Expect` via [`onBeforeSendHeaders`](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/onBeforeSendHeaders) WebExtension API This means we now have a workaround for #480 that works in both Firefox and Chromium. Details: #480 (comment) & ipfs/kubo#5168 (comment) Closes #480
Fix here: ipfs/go-ipfs-cmds#116 It manages to only break the connection if there's a body to read (at least it should). I've tested it with @lidel's app and it appears to work. Could test out that PR? |
@Stebalien my gx is bit rusty, what are the steps to rebuild go-ipfs with that dependency? |
@lidel |
@Stebalien tested fix from ipfs/go-ipfs-cmds#116 (disabled Companion's workarounds for the duration of the test) and it solves the issue for all samples that were known to me to trigger the error. |
This is a workaround to have clients behave properly with the /add endpoint by asking them to close connections when done, effectively disabling keep-alive for this. This means we don't need to disable keep-alives fully on all servers, since the rest of endpoints are not affected (they are not streaming endpoints). Reference ipfs/kubo#5168 License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
Fixed in master. |
This has been fixed! golang/go#15527 (comment) |
Version information:
OS: two Linux boxes (one was Gentoo second was Debian)
IPFS Node:
HTTP API Client:
js-ipfs-api 22.1.1
running in browser contextType:
Bug
Note: This issue is about error in response produced by go-ipfs. There is a separate bug for the lack of proper handling of partial errors in
js-ipfs-api
at https://github.com/ipfs/js-ipfs-api/issues/797)Description:
Sometimes (for specific payloads in browser context) the HTTP API for
ipfs.files.add
provided by go-ipfs returns thehttp: invalid Read on closed Body
error.It is especially problematic when adding multiple files at once, because error is returned in the middle of response, along with successful entries with the same payload:
How to Reproduce
The issue does not seem to appear when
curl
is used, it seems to be specific to browser context and the wayjs-ipfs-api
makes requests to HTTP API.I've found two ways to reproduce/investigate it:
A) By inspecting recorded HTTP interaction
Below is a recorded HTTP Archive (HAR) of interaction that produced the error:
Archive%2018-06-28%2015-34-47.har
Interaction was uploading these sample files with demo app (details below).
B) By Using Demo App
Turns out the
.zip
with demo app triggers the issue 🙃 , so its easy to reproduce::5001
upload-multiple-files-via-browser-ipfs-api-bug-demo.zip
(uses
ipfs-api ^22.1.1
and uploads files viaipfs.files.add
withwrapWithDirectory: true
)npm install && npm start
, then open form at http://localhost:3000upload-multiple-files-via-browser-ipfs-api-bug-demo.zip
The text was updated successfully, but these errors were encountered: