service-worker-gateway
service-worker-gateway copied to clipboard
Implement Retrieval Timeout
Service Worker should have a configurable Retrieval Timeout, set to 30s by default to match current UX of Kubo, Rainbow, ipfs.io / dweb.link:
Gateway.RetrievalTimeout at kubo/docs/config.md:
Timeout behavior:
- Time to first byte: Returns 504 Gateway Timeout if the gateway cannot start writing within this duration (e.g., stuck searching for providers)
- Time between writes: After first byte [block], timeout resets with each write [block]. Response terminates if no new data [block] can be written within this duration
Prior art GO code:
- https://github.com/ipfs/kubo/pull/10905
- https://github.com/ipfs/boxo/pull/994
This is already partially implemented though it doesn't reset between blocks.
We probably don't need to go to the level of blocks specifically, we can just wrap the @helia/verified-fetch response body stream and reset a timer every time any chunk of data is sent to the caller.