Re: [w3c/ServiceWorker] ServiceWorker lifetime and respondWith() with a user-constructed ReadableStream (#882)

Don't know if there is any Firefox developer in here. but fyi, FF v102 started to support transferable ReadableStream and that broke quite many downloads for many fellow user of my StreamSaver.js lib. 

I deliberately didn't do any postMessage hack to keep the service worker alive. cuz chrome could just take a ReadableStream from the main thread, pass it to the service worker and respond with that ReadableStream and then terminate the service worker cuz it was not in use. the service worker didn't try to read or enqueue any data from the stream inside of the service worker. it just forwared the transfered readable stream from the main thread -> service worker -> eventually `evt.respondWith(new Response(stream))`

i expected that FF would follow suit. but it didn't. the transferable stream detection took over how my script behaved differently. FF would transfer the stream and no postMessages where then sent to the service worker to keep it alive. b/c i tough it would not be necessary. but it was 😞 
Firefox killed the service worker after 30s and terminated the response along with it that was instantiated with a ReadableStream coming from the main thread. 

now all browser use the postMessage hack to keep the service worker alive.

---

with that said, can we shine any light on how the service worker should behave if "ServiceWorker lifetime and respondWith() with a user-constructed ReadableStream" should behave?

I would say: 
- As long as there is any resource (tab or download) that consumes the response should not deliberately terminate the service worker after a hard timeout (it should let it finish, even if it's a 3h long movie that is being streamed for 3h) 
- if the stream is released and can be piped in the background, then fine go ahead and kill the service worker after x sec. 
- or fix the #1566 and honor the request of `evt.waitUntil` as long as there is any tab open.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/882#issuecomment-1445191281

You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/issues/882/1445191281@github.com>

Received on Saturday, 25 February 2023 19:51:31 UTC