Skip to content

Retire controlled Service Worker fetches on abort and timeout #340

Description

@wieslawsoltes

Parent resource issue: #266
Webview epic: #264
Host-message streaming: #329
Connected resources: #308

Proven gap

Current fetch(..., { signal }) races the native fetch promise and rejects the JavaScript caller when the signal aborts, but it does not cancel the underlying controlled Service Worker fetch. A worker whose respondWith() promise remains pending keeps one of the 32 active fetch slots until the independent 30-second waiter expires, and that timeout does not explicitly retire the worker-side request. Repeated aborts can therefore exhaust the controlled-fetch cap and retain worker promises, host-message stream writers, or response-body leases after the caller is gone.

Navigation and unregister retire some client state, but there is no per-request cancellation identity connecting the Window fetch task to the Service Worker fetch queue/promise.

Scope

  • Give each abortable Window fetch a bounded native request identity and connect it to its controlled Service Worker request.
  • Propagate AbortSignal cancellation, native 30-second timeout, navigation, unregister, and shutdown to queued or dispatched worker fetches.
  • Release the 32-fetch slot exactly once and reject/ignore every late response, host chunk, or settlement for a canceled request.
  • Preserve browser AbortError/custom abort reason behavior and removal of abort listeners after settlement.
  • Keep parser/connected element loads, localResourceRoots admission, localhost mapping, CSS routing, and product-specific message channels outside this slice.

Acceptance

  • Chromium and native contracts cover pre-aborted signals, abort before worker dispatch, abort while respondWith() is pending, custom abort reasons, completion-vs-abort races, and late worker settlement.
  • Thirty-two canceled controlled requests immediately free capacity for a succeeding request; no 30-second tail remains.
  • Timeout, navigation, unregister, and shutdown leave zero queued/active controlled fetches and no retained response-body bytes.
  • One hundred abort/settle cycles retain no more than 8 MiB V8 heap and 64 MiB RSS after warm-up, with p95 cancellation-to-capacity-release <= 100 ms.
  • Existing Preserve range and cache headers in controlled fetches #323 range/header/body caps and Stream host-supplied Service Worker responses with bounded backpressure #329 streaming/backpressure contracts remain green.

Proposed focused PR

One product-neutral controlled-fetch cancellation tranche from current main, limited to the native fetch/Service Worker state machine and a reduced WebPlatformSubset contract plus native lifecycle/performance gate.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions