Skip to content

net: Return FetchController from fetch - #49263

Closed
TimvdLippe wants to merge 1 commit into
servo:mainfrom
TimvdLippe:net-return-controller-from-fetch
Closed

TimvdLippe wants to merge 1 commit into
servo:mainfrom
TimvdLippe:net-return-controller-from-fetch

Conversation

@TimvdLippe

Copy link
Copy Markdown
Contributor

This is the first step in passing the controller back to the caller of fetch. The response was only used for preloading, which now is implemented as a full target with complete steps. It was also used in the web page content handler, which I don't know yet how to port, but that code has also not been working anyways. Therefore, I opted to not fully fix that, since it is not clear to me from the spec what the desired behavior is in the first place.

Part of #49262

Testing: no behavior change except for non-completed page handler feature

This is the first step in passing the controller back to the caller of
`fetch`. The response was only used for preloading, which now is
implemented as a full target with complete steps. It was also used in
the web page content handler, which I don't know yet how to port, but
that code has also not been working anyways. Therefore, I opted to not
fully fix that, since it is not clear to me from the spec what the
desired behavior is in the first place.

Part of servo#49262

Testing: no behavior change except for non-completed page handler
feature

Signed-off-by: Tim van der Lippe <[email protected]>
@TimvdLippe
TimvdLippe requested a review from jdm October 25, 2026 17:07
@TimvdLippe TimvdLippe added the T-linux-wpt Do a try run of the WPT label Oct 25, 2026
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 25, 2026
@github-actions github-actions Bot removed the T-linux-wpt Do a try run of the WPT label Oct 25, 2026
@github-actions

Copy link
Copy Markdown

🔨 Triggering try run (#40214914470) for Linux (WPT)

"Failed to preload".into(),
))
})
.unwrap_or(response.clone());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cloning the response is unfortunate here, but I don't think there is any way around for now. The spec wants us to send the full response in https://fetch.spec.whatwg.org/#fetch-finale in the last step. (The spec has also changed since our implementation, since "fetch response handover" didn't exist yet when we implemented fetch)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I also don't have any ideas yet besides wrapping the response in a Rc. It's unfortunate.

@github-actions

Copy link
Copy Markdown

Test results for linux-wpt from try job (#40214914470):

Flaky unexpected result (18)
  • FAIL [expected PASS] /content-security-policy/img-src/shared-stylesheet-image-set-cache-bypass-strict-first.html
  • OK /css/css-animations/event-order.tentative.html (#39000)
    • PASS [expected FAIL] subtest: Same events on pseudo-elements follow the prescribed order
  • FAIL [expected PASS] /css/css-backgrounds/background-size-042.html
  • OK /html/browsers/browsing-the-web/navigating-across-documents/006.html
    • PASS [expected FAIL] subtest: Link with onclick form submit and href navigation
  • OK /html/browsers/browsing-the-web/navigating-across-documents/navigation-unload-same-origin-fragment.html (#20768)
    • PASS [expected FAIL] subtest: Tests that a fragment navigation in the unload handler will not block the initial navigation
  • TIMEOUT /html/browsers/history/the-history-interface/001.html (#12580)
    • PASS [expected FAIL] subtest: traversing history must also traverse hash changes
  • TIMEOUT [expected OK] /html/browsers/windows/consume-user-activation/window-open-multi-global.html (#47399)
    • TIMEOUT [expected FAIL] subtest: window.open() and consuming user activation with multiple globals in play

      Test timed out
      

  • TIMEOUT /html/semantics/embedded-content/media-elements/autoplay-default-permissions-policy.https.sub.html (#46805)
    • TIMEOUT [expected PASS] subtest: Default "autoplay" feature policy ["self"] allows the top-level document.

      Test timed out
      

  • OK /infrastructure/testdriver/click_iframe.html (#47688)
    • FAIL [expected PASS] subtest: TestDriver click on a document in an iframe

      Unhandled rejection: assert_unreached: click failed Reached unreachable code
      

  • FAIL [expected PASS] /mathml/presentation-markup/operators/mo-lspace-rspace-dynamic.html (#49168)
  • PASS [expected FAIL] /mathml/presentation-markup/operators/mo-single-char-and-children.html
  • OK /mixed-content/tentative/autoupgrades/audio-upgrade.https.sub.html (#41697)
    • FAIL [expected PASS] subtest: Audio autoupgraded

      assert_equals: Length expected 1 but got Infinity
      

  • TIMEOUT [expected OK] /pointerevents/compat/pointerevent_touch-action_two-finger_interaction.html
    • NOTRUN [expected PASS] subtest: touch two-finger pan on 'touch-action: pan-x pan-y'
    • NOTRUN [expected FAIL] subtest: touch two-finger pan on 'touch-action: pinch-zoom'
  • OK /sanitizer-api/sanitizer-inert-document.html (#45260)
    • PASS [expected FAIL] subtest: Test whether setHTML loads the image.
    • FAIL [expected PASS] subtest: Test whether setHTMLUnsafe loads the image.

      promise_test: Unhandled rejection with value: "The server observed a request. It shouldn't have."
      

  • TIMEOUT [expected PASS] /streams/readable-streams/crashtests/from-cross-realm.https.html
  • OK /upgrade-insecure-requests/gen/sharedworker-classic-data.meta/upgrade/websocket.https.html
    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for websocket to cross-ws-downgrade origin and no-redirect redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for websocket to same-ws-downgrade origin and no-redirect redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

  • OK /upgrade-insecure-requests/gen/sharedworker-module-data.meta/upgrade/fetch.https.html
    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for fetch to cross-http-downgrade origin and downgrade redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for fetch to cross-http-downgrade origin and no-redirect redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for fetch to cross-https origin and downgrade redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for fetch to same-http-downgrade origin and downgrade redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for fetch to same-http-downgrade origin and no-redirect redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

    • FAIL [expected PASS] subtest: Upgrade-Insecure-Requests: Expects allowed for fetch to same-https origin and downgrade redirection from https context.

      assert_equals: The resource request should be 'allowed'. expected "allowed" but got "blocked"
      

  • OK /webxr/xrSession_features_deviceSupport.https.html (#24357)
    • FAIL [expected PASS] subtest: Immersive XRSession requests with no supported device should reject

      assert_unreached: Should have rejected: undefined Reached unreachable code
      

Stable unexpected results that are known to be intermittent (7)
  • OK /beacon/beacon-basic.https.window.html (#41723)
    • FAIL [expected PASS] subtest: Payload size restriction should be accumulated: type = string

      assert_false: expected false got true
      

  • OK /css/css-fonts/variations/at-font-face-font-matching.html (#20684)
    • FAIL [expected PASS] subtest: Matching font-weight: '430' should prefer '420 440' over '450 460'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

    • FAIL [expected PASS] subtest: Matching font-style: 'oblique 20deg' should prefer 'oblique 10deg' over 'oblique 0deg'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

    • FAIL [expected PASS] subtest: Matching font-style: 'oblique 20deg' should prefer 'oblique -50deg -20deg' over 'oblique -40deg -30deg'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

    • FAIL [expected PASS] subtest: Matching font-style: 'oblique -20deg' should prefer 'oblique -10deg' over 'oblique 0deg'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

  • TIMEOUT [expected OK] /html/browsers/browsing-the-web/navigating-across-documents/cross-origin-top-navigation-with-user-activation-in-parent.window.html (#48205)
    • TIMEOUT [expected FAIL] subtest: Cross-origin top navigation is blocked without user activation, even if the parent has user activation

      Test timed out
      

  • OK [expected TIMEOUT] /html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/form-requestsubmit.html (#44098)
    • FAIL [expected TIMEOUT] subtest: Replace before load, triggered by formElement.requestSubmit()

      assert_equals: expected "http://web-platform.test:8000/common/blank.html?thereplacement=" but got "http://web-platform.test:8000/html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/resources/code-injector.html?pipe=sub(none)&amp;code=%0A%20%20%20%20const%20form%20%3D%20document.createElement(%22form%22)%3B%0A%20%20%20%20form.action%20%3D%20%22%2Fcommon%2Fblank.html%22%3B%0A%0A%20%20%20%20const%20input%20%3D%20document.createElement(%22input%22)%3B%0A%20%20%20%20input.type%20%3D%20%22hidden%22%3B%0A%20%20%20%20input.name%20%3D%20%22thereplacement%22%3B%0A%20%20%20%20form.append(input)%3B%0A%0A%20%20%20%20document.currentScript.before(form)%3B%0A%20%20%20%20form.requestSubmit()%3B%0A%20%20"
      

  • CRASH [expected TIMEOUT] /html/browsers/history/the-location-interface/location_replace_session_history.html (#41896)
  • OK /html/webappapis/user-prompts/print-during-unload.html (#35944)
    • FAIL [expected PASS] subtest: print() during unload

      assert_array_equals: expected property 1 to be "destination" but got "error: window.print is not a function" (expected array ["start", "destination"] got ["start", "error: window.print is not a function"])
      

  • FAIL [expected PASS] /mathml/presentation-markup/operators/operator-dictionary-empty-and-three-chars.html (#49173)

@github-actions

Copy link
Copy Markdown

✨ Try run (#40214914470) succeeded.

}

// Step 11.6. If processResponse is given, then call processResponse with response.
self.preload_target.process_response_eof(request, response);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The self.preloaded_resources field is still locked when we call this. We should unlock it first.

"Failed to preload".into(),
))
})
.unwrap_or(response.clone());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I also don't have any ideas yet besides wrapping the response in a Rc. It's unfortunate.

let request_id = request.id;

// Step 17: Run main fetch given fetchParams.
let controller = fetch_params.controller.clone();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to clone this here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think eventually we need to clone before we call main_fetch, because the spec expects us to not await the result of main_fetch. See step 11 of https://fetch.spec.whatwg.org/#concept-main-fetch where the first call to main fetch has recursive false, hence all these steps happen in parallel.

In this PR I don't think cloning is required, but in a follow-up where both the future of main_fetch and the return value in the method need to have the controller, I think we will need to clone it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer to leave changes like that until they are required, because it helps me better understand the actual flow of data.

pub state: FetchControllerState,
}

pub type ShareableFetchController = Arc<Mutex<FetchController>>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this necessary? What code needs to mutate the values inside it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The spec expects the controller to be passed onto the caller, which in this case is the script thread. Currently the script thread creates a FetchController separate from the fetch thread, which also creates a controller. The controller from the fetch thread would need to be passed onto the caller in the script thread, so that the controller created by the script thread is no longer required.

Once we do that, we can implement the spec more as intended and fix the issue mentioned in #49262 namely that the fetch controller needs to be part of the navigation params (https://html.spec.whatwg.org/multipage/browsing-the-web.html#populating-a-session-history-entry:navigation-params-fetch-controller-2) so that we can implement the logic in step 15 of https://html.spec.whatwg.org/multipage/document-lifecycle.html#initialise-the-document-object

Since the controller needs to be shared by 2 threads, I thought that it would need to be an Arc<Mutex<>>, wouldn't it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One wrinkle here is that the two controller instances can live in separate processes when multiprocess mode is enabled. That means they won't actually be shared in that case, and the Arc is a bit of a lie. To avoid confusion and different behaviours, we should probably model it the same way for single process.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah right. In that case, this approach doesn't work at all. I think we need to have a ScriptFetchController that would communicate with the fetch thread for obtaining timing or terminating etc... What do you think about that?

The ScriptFetchController would then have a timing_info() method that would send a message to the fetch thread to obtain the timing info and send it over to the script thread.

Also, to make that all work, I think we first need to tackle the "the servoparser shouldn't create the document, as that should happen in https://html.spec.whatwg.org/multipage/document-lifecycle.html#initialise-the-document-object instead"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ScriptFetchController sounds reasonable!

let request2 = request.clone();
let context2 = context.clone();
Box::pin(async move { fetch(request2, &mut DiscardFetch, &context2).await })
// TODO: Figure out how to take the fetch response and return that instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this requires 1) awaiting the fetch future, 2) using a fetch target that can receive the Response and cloning that to resolve the future.

@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 26, 2026
lukewarlow pushed a commit to lukewarlow/servo that referenced this pull request Oct 30, 2026
…o#48793)

When the cors_flag would be set, we would always set the origin back to
an opaque origin. This causes same-site and cross-site computation to
break, since we would incorrectly reset the origin back to an opaque for
perfectly fine origins.

Instead, remove that step (which also wasn't in the spec) and rewrite
the logic to only perform when the request mode is actually Cors.

Closes servo#49262 (no longer required)
Closes servo#49263 (now obsolete)

Testing: most fetch metadata tests now pass

---------

Signed-off-by: Tim van der Lippe <[email protected]>
Signed-off-by: Tim van der Lippe <[email protected]>
Co-authored-by: Martin Robinson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-needs-code-changes Changes have not yet been made that were requested by a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants