w3c / w3c/ServiceWorker

ServiceWorker lifetime and respondWith() with a user-constructed ReadableStream

Open
#882 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

apr-2017-f2f-v1 decided
Dominant language
Bikeshed
Stars
3.6k
Forks
324
Avg merge
14d 22h
Merged PRs (30d)
1

Description

Branched from https://github.com/yutakahirano/fetch-with-streams/issues/63#issuecomment-207453714

respondWith() with a user-constructed ReadableStream

When a user-constructed ReadableStream is being consumed by respondWith(), respondWith() doesn't know what's happening inside the ReadableStream. The ReadableStream interface of the instance facing respondWith() doesn't allow either scraping out its contents or knowing ReadableStreamDefaultController.close() is invoked (note that a ReadableStream doesn't always have ReadableStreamDefaultController behind it).

Until all the chunks are read out from the ReadableStream, it's holding some JS objects representing the underlying source and chunks in its queue. So, we want to keep the ServiceWorker alive until they're drained.

Also, note that only respondWith() can observe the ReadableStream's state when respondWith() is consuming it. It could work but is not good that we tell the instance to wait for to SW like evt.waitUntilClosed(aStream) as Ben suggested at https://github.com/yutakahirano/fetch-with-streams/issues/63#issuecomment-207487623.

evt.respondWith(response, { waitForBody: true }); (https://github.com/yutakahirano/fetch-with-streams/issues/63#issuecomment-207489289) by Ben looks better.

There we could have a timeout to abort receiving chunks even when waitForBody is specified so that badly behaving stream doesn't prolong SW lifetime forever.

respondWith() with a ReadableStream constructed by Fetch API

I agree with Ben's point at https://github.com/yutakahirano/fetch-with-streams/issues/63#issuecomment-207483430. This is also related to the discussion how we realize efficient pipeTo() algorithm. I.e. for certain operations, streams would behave like a simple identifier of data source / destination like file descriptor.

I'll try to standardize all the interfaces for these issues by resuming the pipeTo() discussion threads.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files or tests are named. Start by reviewing the linked fetch-with-streams issue 63 and the discussion of respondWith(), ReadableStream, waitUntilClosed(), waitForBody, and pipeTo(). Done requires a settled interface and ServiceWorker lifetime behavior suitable for standardization.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.