whatwg / fetch

Fetch Standard
https://fetch.spec.whatwg.org/
Other
2.12k stars 333 forks source link

Service worker "handle fetch" seems to assume it's called in parallel #1734

Closed domenic closed 9 months ago

domenic commented 9 months ago

What is the issue with the Fetch Standard?

Some time ago we refactored fetch to be callable from everywhere, including the main thread, with callbacks to signal the result.

In this world, fetch calls "handle fetch" without going in parallel. It's assumed that "handle fetch" synchronously returns a response.

Handle fetch does synchronously return a response. But it does so with various "Wait" calls, e.g.

Wait for task to have executed or for handleFetchFailed to be true.

In general it's very unclear to me exactly how Handle Fetch is anticipating being called, actually... sometimes it explicitly goes in parallel itself. Sometimes it manipulates main-thread objects like promises. Sometimes it queues tasks, as if it was already in parallel. But, probably it's best to assume it's supposed to be executing in parallel.

annevk commented 9 months ago

Fetch itself is always in parallel at that point, no? Per step 11 of https://fetch.spec.whatwg.org/#concept-main-fetch. (To be clear, no disagreement that this can all be improved.)

domenic commented 9 months ago

Yep, my eyes totally glazed over that step; sorry!