{"action":"created","issue":{"url":"https://api.github.com/repos/ipfs/go-ipfs/issues/5168","repository_url":"https://api.github.com/repos/ipfs/go-ipfs","labels_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/5168/labels{/name}","comments_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/5168/comments","events_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/5168/events","html_url":"https://github.com/ipfs/go-ipfs/issues/5168","id":336631685,"node_id":"MDU6SXNzdWUzMzY2MzE2ODU=","number":5168,"title":"Error while files.add over HTTP API (http: invalid Read on closed Body)","user":{"login":"lidel","id":157609,"node_id":"MDQ6VXNlcjE1NzYwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/157609?v=4","gravatar_id":"","url":"https://api.github.com/users/lidel","html_url":"https://github.com/lidel","followers_url":"https://api.github.com/users/lidel/followers","following_url":"https://api.github.com/users/lidel/following{/other_user}","gists_url":"https://api.github.com/users/lidel/gists{/gist_id}","starred_url":"https://api.github.com/users/lidel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lidel/subscriptions","organizations_url":"https://api.github.com/users/lidel/orgs","repos_url":"https://api.github.com/users/lidel/repos","events_url":"https://api.github.com/users/lidel/events{/privacy}","received_events_url":"https://api.github.com/users/lidel/received_events","type":"User","site_admin":false},"labels":[{"id":109732110,"node_id":"MDU6TGFiZWwxMDk3MzIxMTA=","url":"https://api.github.com/repos/ipfs/go-ipfs/labels/bug","name":"bug","color":"fc2929","default":true},{"id":172465046,"node_id":"MDU6TGFiZWwxNzI0NjUwNDY=","url":"https://api.github.com/repos/ipfs/go-ipfs/labels/commands","name":"commands","color":"207de5","default":false}],"state":"open","locked":false,"assignee":{"login":"Stebalien","id":310393,"node_id":"MDQ6VXNlcjMxMDM5Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/310393?v=4","gravatar_id":"","url":"https://api.github.com/users/Stebalien","html_url":"https://github.com/Stebalien","followers_url":"https://api.github.com/users/Stebalien/followers","following_url":"https://api.github.com/users/Stebalien/following{/other_user}","gists_url":"https://api.github.com/users/Stebalien/gists{/gist_id}","starred_url":"https://api.github.com/users/Stebalien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stebalien/subscriptions","organizations_url":"https://api.github.com/users/Stebalien/orgs","repos_url":"https://api.github.com/users/Stebalien/repos","events_url":"https://api.github.com/users/Stebalien/events{/privacy}","received_events_url":"https://api.github.com/users/Stebalien/received_events","type":"User","site_admin":false},"assignees":[{"login":"Stebalien","id":310393,"node_id":"MDQ6VXNlcjMxMDM5Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/310393?v=4","gravatar_id":"","url":"https://api.github.com/users/Stebalien","html_url":"https://github.com/Stebalien","followers_url":"https://api.github.com/users/Stebalien/followers","following_url":"https://api.github.com/users/Stebalien/following{/other_user}","gists_url":"https://api.github.com/users/Stebalien/gists{/gist_id}","starred_url":"https://api.github.com/users/Stebalien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stebalien/subscriptions","organizations_url":"https://api.github.com/users/Stebalien/orgs","repos_url":"https://api.github.com/users/Stebalien/repos","events_url":"https://api.github.com/users/Stebalien/events{/privacy}","received_events_url":"https://api.github.com/users/Stebalien/received_events","type":"User","site_admin":false}],"milestone":null,"comments":9,"created_at":"2018-06-28T13:53:59Z","updated_at":"2018-07-05T09:54:01Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"> This bug was originally found in https://github.com/ipfs-shipyard/ipfs-companion/issues/480.\r\n> 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.\r\n\r\n#### Version information:\r\n\r\nOS: two Linux boxes (one was Gentoo second was Debian)\r\n\r\nIPFS Node:\r\n```\r\ngo-ipfs version: 0.4.16-rc1-b183da3\r\nRepo version: 7\r\nSystem version: amd64/linux\r\nGolang version: go1.10.3\r\n```\r\nHTTP API Client:  `js-ipfs-api 22.1.1` running in browser context\r\n\r\n\r\n#### Type:\r\n<!-- Bug, Feature, Enhancement, Etc -->\r\nBug\r\n\r\n**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)\r\n\r\n### Description:\r\n\r\nSometimes (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.\r\n\r\nIt 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:\r\n\r\n![screenshot_18](https://user-images.githubusercontent.com/157609/42037085-bec1c3ce-7ae7-11e8-9b5b-f3612988cd0d.png)\r\n\r\n### How to Reproduce\r\n\r\nThe 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.\r\n\r\nI've found two ways to reproduce/investigate it:\r\n\r\n#### A) By inspecting recorded HTTP interaction\r\n\r\nBelow is a recorded HTTP Archive ([HAR](https://en.wikipedia.org/wiki/.har)) of interaction that produced the error:\r\n[Archive%2018-06-28%2015-34-47.har](https://ipfs.io/ipfs/QmaRX42xQ9FyPDdpehZpHGRo7es1iZfWhtxw3NkVpAu6wP)\r\n\r\nInteraction was uploading [these sample files](https://ipfs.io/ipfs/QmUGmyGCJEntjyxgcBmptkZ34k7PsgnCzXPoqwiWBDTK6L) with demo app (details below).\r\n\r\n#### B) By Using Demo App\r\n\r\nTurns out the `.zip` with demo  app triggers the issue :upside_down_face: , so its easy to reproduce:\r\n\r\n1. Expose API of go-ipfs 0.4.15 or 0.4.16-rc1 locally on port `:5001`\r\n2. Download demo app:[`upload-multiple-files-via-browser-ipfs-api-bug-demo.zip`](https://github.com/ipfs/go-ipfs/files/2145563/upload-multiple-files-via-browser-ipfs-api-bug-demo.zip)\r\n  (uses `ipfs-api ^22.1.1` and uploads files via `ipfs.files.add` with `wrapWithDirectory: true`)\r\n3. Build it and start via `npm install && npm start`, then open form at http://localhost:3000\r\n4. Reproduce using samples known to trigger issue at go-ipfs\r\n   - Sample 1: upload single file: [`upload-multiple-files-via-browser-ipfs-api-bug-demo.zip`](https://github.com/ipfs/go-ipfs/files/2145563/upload-multiple-files-via-browser-ipfs-api-bug-demo.zip)\r\n       - This should produce [error](https://user-images.githubusercontent.com/157609/42034747-4742caa6-7ae1-11e8-873b-42f3260255d1.png)\r\n   - Sample 2: upload [these three files at once](https://ipfs.io/ipfs/QmUGmyGCJEntjyxgcBmptkZ34k7PsgnCzXPoqwiWBDTK6L)\r\n      - This should produce [error](https://user-images.githubusercontent.com/157609/42034774-5ca014bc-7ae1-11e8-8af3-ba3401169513.png)\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ipfs/go-ipfs/issues/comments/402670026","html_url":"https://github.com/ipfs/go-ipfs/issues/5168#issuecomment-402670026","issue_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/5168","id":402670026,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjY3MDAyNg==","user":{"login":"lidel","id":157609,"node_id":"MDQ6VXNlcjE1NzYwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/157609?v=4","gravatar_id":"","url":"https://api.github.com/users/lidel","html_url":"https://github.com/lidel","followers_url":"https://api.github.com/users/lidel/followers","following_url":"https://api.github.com/users/lidel/following{/other_user}","gists_url":"https://api.github.com/users/lidel/gists{/gist_id}","starred_url":"https://api.github.com/users/lidel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lidel/subscriptions","organizations_url":"https://api.github.com/users/lidel/orgs","repos_url":"https://api.github.com/users/lidel/repos","events_url":"https://api.github.com/users/lidel/events{/privacy}","received_events_url":"https://api.github.com/users/lidel/received_events","type":"User","site_admin":false},"created_at":"2018-07-05T09:54:01Z","updated_at":"2018-07-05T09:54:01Z","author_association":"CONTRIBUTOR","body":"@Stebalien ok, this is quite serious bug: setting `Connection: close` is not something javascript clients can do.  WebExtension APIs are a mixed bag: Chrome also does not allow any change to this header.\r\n\r\nAre 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 `http` stack?\r\n\r\nSomething like:\r\n1. Clients sends request to `/api/v0/api` with additional,\r\n    custom HTTP header `X-Ipfs-Connection: close` \r\n2. go-ipfs acts like it received `Connection: close` \r\n"}}
{"actor":{"display_login":"lidel"}}