Description
This bug was originally found in ipfs/ipfs-companion#480.
Since then I was able to confirm issue originates betweenjs-ipfs-api
and HTTP API exposed bygo-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
(usesipfs-api ^22.1.1
and uploads files viaipfs.files.add
withwrapWithDirectory: 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
- Sample 1: upload single file:
upload-multiple-files-via-browser-ipfs-api-bug-demo.zip
- This should produce error
- Sample 2: upload these three files at once
- This should produce error
- Sample 1: upload single file: