Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recovering from start failures #1503

Open
ytausky opened this issue Feb 3, 2020 · 5 comments
Open

Recovering from start failures #1503

ytausky opened this issue Feb 3, 2020 · 5 comments

Comments

@ytausky
Copy link

ytausky commented Feb 3, 2020

Currently when a service worker fails to start, the result is a network error. A service worker failing to start can happen due to a bad script or other non-transient errors, so it would be more useful for the user to have a fallback that bypasses the service worker in this case.

@bzbarsky
Copy link

bzbarsky commented Feb 3, 2020

If I understand correctly, the fallback behavior is in fact what Chrome implements, and this is causing compat problems because some sites are relying on it. @wanderview @foolip

@wanderview
Copy link
Member

Can you define what you mean by "bad script"? The installation should not allow a bad script to be persisted. Are we discussing storage corruption or other browser internal error?

In any case, I think we should not break the site in these cases. I think failing safe by falling back should be preferred since there is nothing the site can do to fix the issue.

So I would be in favor of changing step 23 here:

https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm

@ytausky
Copy link
Author

ytausky commented Feb 3, 2020

By "bad script" I mean one that has an error on a subsequent evaluation and thus cannot be started. For example, by using the current time as part of the URL of an imported script it's possible to create a worker script that evaluates correctly the first time, but fails on a subsequent run (because it tries to import a new script).

@wanderview
Copy link
Member

Hmm, a programming error like that does seem like it should fail the request. But I still feel other internal causes of the SW failing to start should fallback. Although I would be happy if they all fell back if that is easier.

@mattto @jakearchibald what do you think?

@mfalken
Copy link
Member

mfalken commented Feb 4, 2020

https://w3c.github.io/ServiceWorker/#run-service-worker-algorithm returns failure or the Completion returned from https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script.

If a runtime error occurs, it returns a Completion containing the error (an "abrupt completion").

If the script couldn't run due to an internal error (the browser couldn't run the worker to completion), it returns failure.

Currently the spec says that failure results in a network error, but on an uncaught runtime error the service worker is considered running and it dispatches the fetch event as usual.

Only the Update algorithm cares about runtime errors at step 18:

  1. Let runResult be the result of running the Run Service Worker algorithm with worker and forceBypassCache.
  2. If runResult is failure or an abrupt completion, then:
    18.1 Invoke Reject Job Promise with job and TypeError.

Chrome is doing fallback in both cases, whereas the spec says only do it on runtime error. I agree the behavior is a bit magical. The fallback was done as a safeguard.

We should also consider the case like when the user disables JS. In this case, I believe Run Service Worker will return failure. We probably want to "fallback" in this case though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants