Skip to content

Flutter web service worker caches error response #99671

@ikenox

Description

@ikenox

flutter_service_worker.js seems to cache the response even if the response is 4XX/5XX error.
https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/build_system/targets/web.dart#L669

And, the service worker caches the response during the resource's hash is identical.
https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/build_system/targets/web.dart#L616

As a result, the service worker still uses the cache of the error response after the error is recovered, because the target resource's hash is not changed.
Is it expected behavior? Or, should the cacheing strategy be improved?

Steps to Reproduce

  1. Request to some static resource e.g. .js file
  2. The request failed with an error
    • In my case it is 401 Basic Authentication failure, but I think the same thing will occur in other situation e.g. CDN is down.
  3. The error response is cached by flutter service worker
  4. Recovered from the error
  5. Request to the target resource again

Expected results:

The resource file is loaded successfully

Actual results:

The cached error is still returned by the service worker

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 2.10Found to occur in 2.10found in release: 2.11Found to occur in 2.11frameworkflutter/packages/flutter repository. See also f: labels.good first issueRelatively approachable for first-time contributorshas reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions