This bug was originally found in ipfs/ipfs-companion#480.
Since then I was able to confirm issue originates between js-ipfs-api and HTTP API exposed by go-ipfs and created a demo app that reproduced issue on two separate machines.
Version information:
OS: two Linux boxes (one was Gentoo second was Debian)
IPFS Node:
go-ipfs version: 0.4.16-rc1-b183da3
Repo version: 7
System version: amd64/linux
Golang version: go1.10.3
HTTP API Client: js-ipfs-api 22.1.1 running in browser context
Type:
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 the http: 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 way js-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:
- Expose API of go-ipfs 0.4.15 or 0.4.16-rc1 locally on port
:5001
- Download demo app:
upload-multiple-files-via-browser-ipfs-api-bug-demo.zip
(uses ipfs-api ^22.1.1 and uploads files via ipfs.files.add with wrapWithDirectory: true)
- Build it and start via
npm install && npm start, then open form at http://localhost:3000
- Reproduce using samples known to trigger issue at go-ipfs
Version information:
OS: two Linux boxes (one was Gentoo second was Debian)
IPFS Node:
HTTP API Client:
js-ipfs-api 22.1.1running 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-apiat https://github.com/ipfs/js-ipfs-api/issues/797)Description:
Sometimes (for specific payloads in browser context) the HTTP API for
ipfs.files.addprovided by go-ipfs returns thehttp: invalid Read on closed Bodyerror.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
curlis used, it seems to be specific to browser context and the wayjs-ipfs-apimakes 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
.zipwith demo app triggers the issue 🙃 , so its easy to reproduce::5001upload-multiple-files-via-browser-ipfs-api-bug-demo.zip(uses
ipfs-api ^22.1.1and uploads files viaipfs.files.addwithwrapWithDirectory: true)npm install && npm start, then open form at http://localhost:3000upload-multiple-files-via-browser-ipfs-api-bug-demo.zip