coasys / ad4m

Agent-centric social network and interoperability dApp framework
https://ad4m.dev
Other
48 stars 10 forks source link

Download file from Cloudflare storage is not working #240

Open kaichaosun opened 1 year ago

kaichaosun commented 1 year ago

In ad4m app, when downloading file from Cloudflare storage, it first gets the presigned url from cloudflare worker, the url looks like this,

https://c47108641b30e868d9950f1adf09c9b1.r2.cloudflarestorage.com/centralized-bootstrap-store/QmZ16K5HG2RgE6Q8xCC5784HG2KGyKPKtkNmGiDb9YQKZg?X-Amz-Date=20230221T014811Z&X-Amz-Expires=86400&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=38a4e3dfb132248c1b6e07389f77691e%2F20230221%2Fauto%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=33fe05ee13446cc277fb65691da0791f2a5c8600190deae246d8c006a73be0c1

It works when I open the above link in browser, but with Nodejs it's broken with ECONNRESET error.

with node-fetch lib, the error is,

FetchError: Invalid response body while trying to fetch https://c47108641b30e868d9950f1adf09c9b1.r2.cloudflarestorage.com/centralized-bootstrap-store/QmZ16K5HG2RgE6Q8xCC5784HG2KGyKPKtkNmGiDb9YQKZg?X-Amz-Date=20230208T172826Z&X-Amz-Expires=86400&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=dbf72009eacc00a2e739260e0105fe65%2F20230208%2Fauto%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=58d40edc56f47946c905bebb871e7f826fdf5673d8e01a679dc4b56ff27fb9ea: Premature close
    at Gunzip.<anonymous> (/Users/kaichaosun/github/flux/language-persistence/node_modules/node-fetch/lib/index.js:400:12)
    at Gunzip.emit (node:events:525:35)
    at Gunzip.emit (node:domain:489:12)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ERR_STREAM_PREMATURE_CLOSE',
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}

with axios lib, the error is,

cause: Error: aborted
      at connResetException (node:internal/errors:705:14)
      at TLSSocket.socketCloseListener (node:_http_client:454:19)
      at TLSSocket.emit (node:events:525:35)
      at TLSSocket.emit (node:domain:489:12)
      at node:net:301:12
      at TCP.done (node:_tls_wrap:588:7) {
    code: 'ECONNRESET'
  }

Reproduce steps,

Potential related issues, https://github.com/serverless-dns/serverless-dns/issues/115 https://github.com/axios/axios/issues/5267

lucksus commented 1 year ago

I had similar weird connection problems to AD4M executor localhost in the JS integration tests. localhost worked but 127.0.0.1 did not (or other way round). The culprit was my VPN. Deactivating the VPN and restarted fixed that. Maybe similar problem here?

Either way, I hope we can get rid of the centralised bootstrap languages soon. We have the large file storage on Holochain in the current sprint..