Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

ipfs.files.add is missing error handling on invalid response from go-ipfs #2864

Closed
@lidel

Description

@lidel

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 create demo app that reproduced issue on two separate machines.

The Bug

Sometimes (for specific multipart payloads in browser context) the ipfs.files.add backed by go-ipfs returns an error in the middle of valid payload:

{"Name":"T-RexFaceEmoji.jpg_original","Hash":"QmR1G8Jq4rNiYwCKyNWEZhNS7i8EWrCpz2xDjKsB9ofi82","Size":"23723"}
{"Name":"FlyingSaucerEmoji.jpg_original","Hash":"QmVWxHcLVHYpFJP6R1ZLBZcpAZsxyFMfU7BU84D2LAMSed","Size":"13071"}
{"Message":"http: invalid Read on closed Body","Code":0,"Type":"error"}

Then, upon receiving this payload, js-ipfs-api does not throw an error, but silently ignores the last line and returns a partial result list with only two first items. (screenshot)

A similar problem occurs for some single file uploads (with wrapWithDirectory: true), js-ipfs-api returns an empty list of responses [] (screenshot)

Note: I created upstream issue for go-ipfs ipfs/kubo#5168, this issue is about handling "partial responses with error" in js-ipfs-api in a way that does not fail silently.

How to Reproduce

Turns out the .zip with sample app triggers the issue 🙃 , so its easy to reproduce:

  1. Expose API of go-ipfs 0.4.15 or 0.4.16-rc1 locally on port :5001
  2. 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)
  3. Build it and start via npm install && npm start, then open form at http://localhost:3000
  4. Reproduce using samples known to trigger issue at go-ipfs

Metadata

Metadata

Assignees

No one assigned

    Labels

    exp/wizardExtensive knowledge (implications, ramifications) requiredkind/bugA bug in existing code (including security flaws)pkg:http-clientIssues related only to ipfs-http-client

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions