Skip to content

Fix: race-network-and-fetch-handler now uses actual |raceResponse| #1777

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

Merged
merged 11 commits into from
Jun 13, 2025

Conversation

yoshisatoyanagisawa
Copy link
Collaborator

@yoshisatoyanagisawa yoshisatoyanagisawa commented Jun 11, 2025

This pull request originates from the work proposed by @monica-ch in #1764, but has been extensively reworked based on review feedback.

This PR corrects response handling for race-network-and-fetch-handler.

Primary Fix: The handler now correctly uses the actual fetch response for |raceResponse| instead of a generic [=network error=].
Minor Improvement: |timingInfo| is now included in the [=network error=], when returned by [=Create Fetch Event and Dispatch=], which simplifies the calling code.


Preview | Diff

@yoshisatoyanagisawa
Copy link
Collaborator Author

@sisidovski @domenic Will you take a look?

yoshisatoyanagisawa and others added 2 commits June 11, 2025 16:37
Apply the suggestion.

Co-authored-by: Domenic Denicola <[email protected]>
Upon the discussion, I understand that the fetch event part will always
be queued.  However, we need to wait for the network response so that we
can reuse it as response on error. We also need to set the proper
|timingInfo| for that case.
@yoshisatoyanagisawa yoshisatoyanagisawa changed the title Isolate fix for race-network-and-fetch-handler stall from PR #1764 Reuse network response on both network and fetch handler failed Jun 11, 2025
@@ -3263,16 +3263,21 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
1. Let |queue| be an empty [=queue=] of [=race result=].
1. Let |raceFetchController| be null.
1. Let |raceResponse| be a [=race response=] whose [=race response/value=] is "<code>pending</code>".
1. Let |networkFetchCompleted| be false.
1. Let |networkFetchResult| be null.
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing setup seems a bit fragile to me. The definition of abort when only operates between steps, and there are only two steps nested under "If aborted"... In fact there is only one step before this PR.

Probably there should be a check on fetchController's state inside the processResponse callback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not confident but I tried to address that with #1779.
Is it what you meant?

As pointed out by the reviewer, the same algorithm can be realized
without |networkFetchCompleted| and |networkFetchResult|.
Let me remove them.
Since `Create Fetch Event And Dispatch` plumb |raceResponse|'s `value`
when it is given, we actually do not need to wait the value.
However, I found that `Create Fetch Event And Dispatch` returns
[=network error=] without the |timingInfo|, it should be propagated
properly.
@yoshisatoyanagisawa yoshisatoyanagisawa changed the title Reuse network response on both network and fetch handler failed Fix: race-network-and-fetch-handler now uses actual |raceResponse| Jun 12, 2025
Copy link
Contributor

@sisidovski sisidovski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand the flow of attaching timing info to network errors, since I have not seen how the callers might use it. But the overall flow looks good to me.

@yoshisatoyanagisawa
Copy link
Collaborator Author

The fetch should plumb the output to w3c/resource-timing#415.
Anyway, let me merge this.

@yoshisatoyanagisawa yoshisatoyanagisawa merged commit a402c93 into w3c:main Jun 13, 2025
2 of 3 checks passed
@yoshisatoyanagisawa yoshisatoyanagisawa deleted the fallback branch June 13, 2025 06:03
github-actions bot added a commit that referenced this pull request Jun 13, 2025
…1777)

SHA: a402c93
Reason: push, by yoshisatoyanagisawa

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit to yoshisatoyanagisawa/ServiceWorker that referenced this pull request Jun 13, 2025
…3c#1777)

SHA: a402c93
Reason: push, by yoshisatoyanagisawa

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit to asleekgeek/ServiceWorker that referenced this pull request Jun 13, 2025
…3c#1777)

SHA: a402c93
Reason: push, by pull[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

4 participants