ipfs / service-worker-gateway

[WIP EXPERIMENT] IPFS Gateway implemented in Service Worker
https://inbrowser.link
Other
23 stars 7 forks source link

Bug: DoH client is missing in-memory cache #59

Open lidel opened 7 months ago

lidel commented 7 months ago

Found the problem can be seen when opening http://localhost:3000/ipns/docs.ipfs.tech without subdomain isolation (e.g. commit 1ef00944c2e99b48207541d5602ebc0150cb512b).

Bunch of times /ipfs/assets/fooo is being resolved (separate problem, but will go away when I finish #30):

image

This edge case surfaced a weakness in our DoH implementation: no local cache. And each time we trigger the same DNS lookup for _dnslink.assets:

image

This works fast only because we added cache in https://github.com/ipshipyard/waterworks-infra/pull/30, but is wasteful and eats into the pool of HTTP request our SW can make.

We need to have in-memory cache which ideally respects TTL from DNS, or at least caches results for 1 minute before asking upstream for an update.

SgtPooki commented 6 months ago

this should be resolved with the latest helia-verified-fetch and new dns updates. will confirm and then resolve

2color commented 6 months ago

I just tried with inbrowser.dev and it seems that even with https://github.com/ipfs/helia-verified-fetch/pull/19 merged and included in the latest release, caching is not working properly. For example see in the second screenshot the logs to the console, most times it isn't resolved from cache.

Screenshot 2024-03-26 at 1 02 20 pm Screenshot 2024-03-26 at 1 06 24 pm

I'm gonna look into this.

2color commented 6 months ago

https://github.com/ipfs/helia-verified-fetch/pull/34 should resolve this.

I was under the false impression that we cache the DNSLink record in the datastore inside @helia/ipns, but that doesn't seem to be the case.

2color commented 6 months ago

Strange that even though we had a bug (resolved by https://github.com/ipfs/helia-verified-fetch/pull/34) with the cache in verified-fetch, it seems that @multiformats/dns used by @helia/ipns wasn't returning from its own cache, which results in many DoH requests.

I'll investigate this

SgtPooki commented 6 months ago

we should be able to close this once the latest @helia/ipns is released

SgtPooki commented 6 months ago

helia ipns is released. we need to update verified-fetch and then update here.

https://github.com/ipfs/helia/releases/tag/ipns-v7.2.0

SgtPooki commented 5 months ago

This issue is resolved on main.

2color commented 5 months ago

Also confirming that from my tests this is resolved!

SgtPooki commented 5 months ago

@aschmahmann reported issues with multiple dns-queries still, but we're having trouble reproducting.

Adin, can you provide the commit hash (found in HTML of root domain) of the site you're using, and a screenshot of what you're seeing for "multiple dns queries" ?

aschmahmann commented 5 months ago

@SgtPooki not able to see within the same browser request the HTML of the root domain to get the commit hash, but I've got this as the loaded js and there's a tag on the JS file name that IIUC should help with versioning.

version

and here are the multiple dns requests

dns-queries
SgtPooki commented 5 months ago

@aschmahmann you should be able to go to <url>/#/ipfs-sw-config to get the config page, which still uses the same index.html, which will have the commit hash. That will make tracking things down a lot easier.

image
SgtPooki commented 4 months ago

@aschmahmann do you still get this error on inbrowser.dev?

SgtPooki commented 4 months ago

confirmed this is happening intermittently for Adin on latest. might be a race condition? might be CORS pre-flight being blocked causing issues? we need to dive in deeper, but it's a hard to repro problem that is inconsistent