filebase / filebase-js

4 stars 5 forks source link

`storeBlob` returned CID but object was not stored in the bucket #8

Closed Yuripetusko closed 7 months ago

Yuripetusko commented 1 year ago

We use storeBlob to save JSON files to IPFS. Recently we had a case where several of our pins using storeBlob returned CID but the file was not uploaded to bucket and not announced to DHT. We repinned the same content and it was eventually correctly uploaded to filebase s3 bucket and announced to DHT.

When looking at code, storeBlob returns CID that is returned from encodeBlob, so there's no guarantee that it was actually uploaded, and my immediate reaction was that this is the cause of this issue, however, after closer inspection, I can see that on the next like there's await FilebaseClient.storeCar(service, car, objectName || cid.toString()), which should throw and error if CID is not returned from filebase server, which shows immediately go to catch clause and call await blockstore.close() instead of returning CID.

So I am puzzled how this happened that CID was returned but the file was not uploaded to the bucket, I was going to submit this simple fix (see screenshot below), but cannot understand why it would be needed as storeCar promise should throw if there's no CID returned in carHeader.Metadata['cid']

image
Yuripetusko commented 1 year ago

Unless the following check is invalid for some reason, hard to reproduce this case when car was not stored, to inspect the header

if (typeof carHeader.Metadata === "undefined" || typeof carHeader.Metadata['cid'] === "undefined") {
      throw new Error(`No CID Returned from Remote`)
    }