web3-storage / web3.storage

DEPRECATED ⁂ The simple file storage service for IPFS & Filecoin
https://web3.storage
Other
503 stars 119 forks source link

w3name possible performance issue #1795

Closed alexanderbkl closed 1 year ago

alexanderbkl commented 2 years ago

I'm using a w3name API to resolve an IPNS link and get a list of all the data stored inside of a JSON stored inside the IPNS. I use useEffect in React, at first it is normal but after a while when issuing many requests, causes a bunch of errors in the console as it is some sort of anti-spam:

Access to fetch at 'https://name.web3.storage/name/k51qzi5uqu5djwrie0ca9wjkmjat59s8zybwnz7q1s68yt50mupsa9e2d2vzhv' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
index.ts:229          GET https://name.web3.storage/name/k51qzi5uqu5djwrie0ca9wjkmjat59s8zybwnz7q1s68yt50mupsa9e2d2vzhv net::ERR_FAILED 429
resolve @ index.ts:229
index.ts:229                  Uncaught (in promise) TypeError: Failed to fetch
    at Module.resolve (index.ts:229:1)
    at async FilesComponent.fr.onload (FilesComponent.js:57:1)

The reason I think it is possible that this might be causing the issue, is because there has been a library migration from Web3Storage Name library to w3name; besides that the incident report matches the time I was testing out the API.

adamalton commented 1 year ago

I'm pretty certain that what's happening here is that you're hitting the rate limit which imposes a maximum of 30 requests in any 10-second period from the same IP. After this, you'll get a 429 response like this:

{
  "code": "ERROR_RATE_LIMITED",
  "message": "You are being rate limited"
}

You can reproduce this just by rapidly refreshing your w3name URL in the browser. I think that the No 'Access-Control-Allow-Origin' header is present on the requested resource. error is just because the 429 status error response doesn't provide that header, but the problem is ultimately that you're being rate limited.

I don't think that this will have been affected at all by the migration from the Web3Storage Name library to the new w3name service; I'm pretty sure it will have had this same limit all along.

So the simple solution is to adapt your application so that it limits its requests to a max of 30 per 10 seconds. I'm not sure of your use case, but it might be worth using the w3name.resolve function, which is rate-limited automatically.