Skip to content

script: Mark fetch-later requests as keep-alive - #41345

Merged
TimvdLippe merged 1 commit into
servo:mainfrom
TimvdLippe:implement-fetch-later-keep-alive
Dec 18, 2025
Merged

TimvdLippe merged 1 commit into
servo:mainfrom
TimvdLippe:implement-fetch-later-keep-alive

Conversation

@TimvdLippe

Copy link
Copy Markdown
Contributor

This implements the required plumbing for the keep-alive flag on requests. The flag already exists on the request object, but now also exists on the builder itself.

The flag is then passed into a canceller. While we could make canceller optional, in many cases it isn't and would require a whole lot more changes. To follow the spec more closely, opted to put the keep_alive flag on the canceller as well.

Note that this doesn't pass any extra fetch-later tests since we are not correctly unloading iframe documents. That will be fixed in a follow-up PR.

Part of #41230

@TimvdLippe
TimvdLippe requested a review from gterzian as a code owner December 17, 2025 11:14
@TimvdLippe TimvdLippe added the T-linux-wpt Do a try run of the WPT label Dec 17, 2025
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 17, 2025
@github-actions github-actions Bot removed the T-linux-wpt Do a try run of the WPT label Dec 17, 2025
@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

Flaky unexpected result (34)
  • TIMEOUT /FileAPI/url/url-in-tags-revoke.window.html (#19978)
    • PASS [expected TIMEOUT] subtest: Fetching a blob URL immediately before revoking it works in <script> tags.
  • OK /_mozilla/css/offset_properties_inline.html (#40543)
    • PASS [expected FAIL] subtest: offsetTop
    • PASS [expected FAIL] subtest: offsetLeft
  • OK /_mozilla/mozilla/getBoundingClientRect.html (#39668)
    • FAIL [expected PASS] subtest: getBoundingClientRect 1

      assert_equals: expected 62 but got 60.35
      

  • CRASH [expected OK] /_mozilla/mozilla/preserve_wrapper_callback.html
  • OK /_mozilla/webxr/create_session.https.html
    • FAIL [expected PASS] subtest: create_session

      can't access property "simulateDeviceConnection", navigator.xr.test is undefined
      

  • OK /_mozilla/webxr/obtain_frame.https.html
    • FAIL [expected PASS] subtest: obtain_frame

      promise_test: Unhandled rejection with value: object "TypeError: can't access property "simulateDeviceConnection", navigator.xr.test is undefined"
      

  • ERROR [expected TIMEOUT] /_mozilla/webxr/sessionavailable.https.html
  • OK /_webgl/conformance/textures/misc/texture-upload-size.html (#21770)
    • PASS [expected FAIL] subtest: WebGL test #45
    • PASS [expected FAIL] subtest: WebGL test #47
    • PASS [expected FAIL] subtest: WebGL test #49
    • PASS [expected FAIL] subtest: WebGL test #51
    • FAIL [expected PASS] subtest: WebGL test #53

      assert_true: Texture was smaller than the expected size 2x2 expected true got false
      

    • FAIL [expected PASS] subtest: WebGL test #55

      assert_true: getError expected: INVALID_VALUE. Was NO_ERROR : when calling texSubImage2D with the same texture upload with offset 1, 1 expected true got false
      

    • FAIL [expected PASS] subtest: WebGL test #57

      assert_true: Texture was smaller than the expected size 2x2 expected true got false
      

    • FAIL [expected PASS] subtest: WebGL test #59

      assert_true: getError expected: INVALID_VALUE. Was NO_ERROR : when calling texSubImage2D with the same texture upload with offset 1, 1 expected true got false
      

    • PASS [expected FAIL] subtest: WebGL test #61
    • PASS [expected FAIL] subtest: WebGL test #63
    • And 10 more unexpected results...
  • FAIL [expected PASS] /css/css-backgrounds/background-size-041.html
  • OK /css/css-fonts/generic-family-keywords-001.html (#37467)
    • PASS [expected FAIL] subtest: @font-face matching for quoted and unquoted generic(nastaliq)
  • OK /css/css-fonts/variations/at-font-face-font-matching.html (#20684)
    • PASS [expected FAIL] subtest: Matching font-style: 'oblique -20deg' should prefer 'oblique 40deg 50deg' over 'italic'
  • OK /fetch/metadata/generated/css-font-face.https.sub.tentative.html (#32732)
    • PASS [expected FAIL] subtest: sec-fetch-mode
    • PASS [expected FAIL] subtest: sec-fetch-user
  • OK /fetch/metadata/generated/css-font-face.sub.tentative.html (#34624)
    • PASS [expected FAIL] subtest: sec-fetch-storage-access - Not sent to non-trustworthy same-site destination
    • FAIL [expected PASS] subtest: sec-fetch-storage-access - Not sent to non-trustworthy cross-site destination

      promise_test: Unhandled rejection with value: object "Error: Failed to query for recorded headers."
      

  • CRASH [expected OK] /html/browsers/browsing-the-web/back-forward-cache/eligibility/dedicated-worker.html
  • OK /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-nosrc.html (#34819)
    • PASS [expected FAIL] subtest: link click
  • OK /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-iframe-contentWindow.html (#28681)
    • FAIL [expected PASS] subtest: load & pageshow events do not fire on contentWindow of <iframe> element created with src='about:blank'

      assert_unreached: load should not be fired Reached unreachable code
      

  • OK /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-window-open.html (#28691)
    • PASS [expected FAIL] subtest: load event does not fire on window.open('about:blank')
  • 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
  • OK /html/browsers/history/the-history-interface/traverse_the_history_3.html (#21383)
    • PASS [expected FAIL] subtest: Multiple history traversals, last would be aborted
  • OK /html/browsers/windows/embedded-opener-remove-frame.html (#23867)
    • FAIL [expected PASS] subtest: opener of discarded auxiliary browsing context

      assert_object_equals: property "get" expected function "function opener() {
          [native code]
      }" got function "function opener() {
          [native code]
      }"
      

  • TIMEOUT [expected OK] /html/interaction/focus/the-autofocus-attribute/document-with-fragment-top.html (#28259)
    • TIMEOUT [expected FAIL] subtest: Autofocus elements in top-level browsing context's documents with "top" fragments should work.

      Test timed out
      

  • TIMEOUT [expected OK] /html/semantics/embedded-content/media-elements/audio_loop_base.html (#41122)
    • NOTRUN [expected PASS] subtest: Check if audio.loop is set to true that expecting the seeking event is fired more than once
  • OK /html/semantics/embedded-content/media-elements/media_fragment_seek.html (#24114)
    • PASS [expected FAIL] subtest: Video should seek to time specified in media fragment syntax
  • TIMEOUT [expected OK] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_other_frame_popup.sub.html (#39702)
    • TIMEOUT [expected FAIL] subtest: Sandboxed iframe can not navigate other frame's popup

      Test timed out
      

  • CRASH [expected OK] /html/webappapis/scripting/processing-model-2/window-onerror-with-cross-frame-event-listeners-5.html
  • 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"])
      

  • OK /preload/link-header-preload-delay-onload.html (#39622)
    • FAIL [expected PASS] subtest: Makes sure that Link headers preload resources and block window.onload after resource discovery

      assert_true: expected true got false
      

  • OK /preload/preload-invalid-resources.html (#39091)
    • PASS [expected FAIL] subtest: Preloading an invalid image (missing) should preload and not re-fetch
  • CRASH [expected OK] /trusted-types/Node-multiple-arguments.html
  • CRASH [expected ERROR] /trusted-types/SharedWorker-setTimeout-setInterval.html
  • OK [expected TIMEOUT] /trusted-types/trusted-types-navigation.html?01-05 (#38975)
    • PASS [expected TIMEOUT] subtest: Navigate a window via anchor with javascript:-urls in report-only mode.
    • PASS [expected NOTRUN] subtest: Navigate a window via anchor with javascript:-urls w/ default policy in report-only mode.
    • PASS [expected NOTRUN] subtest: Navigate a frame via anchor with javascript:-urls in enforcing mode.
  • CRASH [expected OK] /webaudio/the-audio-api/processing-model/feedback-delay-time.html
  • OK /webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching.html (#22849)
    • FAIL [expected PASS] subtest: buffer-stitching-2

      assert_approx_equals: Stitched sine‑wave buffers at sample rate 43800 sample[9606] |5.459857331944544e-20 - -0.8369202017784119| = 0.8369202017784119 > 0.0038986 expected -0.8369202017784119 +/- 0.0038986 but got 5.459857331944544e-20
      

  • OK [expected TIMEOUT] /webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.html (#29053)
    • PASS [expected TIMEOUT] subtest: StorageKey: test 3P about:blank window opened from a 3P iframe
Stable unexpected results that are known to be intermittent (27)
  • OK /FileAPI/url/url-with-fetch.any.worker.html (#21517)
    • FAIL [expected PASS] subtest: Revoke blob URL after calling fetch, fetch should succeed

      promise_test: Unhandled rejection with value: object "TypeError: Network error occurred"
      

  • OK /IndexedDB/idbcursor-continuePrimaryKey-exceptions.any.html (#39277)
    • FAIL [expected PASS] subtest: IDBCursor continuePrimaryKey() on object store cursor

      assert_throws_dom: continuePrimaryKey() should throw if source is not an index function "function() {
              cursor.continuePrimaryKey(2, 2);
            }" threw object "TypeError: cursor.continuePrimaryKey is not a function" that is not a DOMException InvalidAccessError: property "code" is equal to undefined, expected 15
      

  • OK /IndexedDB/idbcursor-continuePrimaryKey-exceptions.any.worker.html (#39277)
    • FAIL [expected PASS] subtest: IDBCursor continuePrimaryKey() on object store cursor

      assert_throws_dom: continuePrimaryKey() should throw if source is not an index function "function() {
              cursor.continuePrimaryKey(2, 2);
            }" threw object "TypeError: cursor.continuePrimaryKey is not a function" that is not a DOMException InvalidAccessError: property "code" is equal to undefined, expected 15
      

  • OK /IndexedDB/idbobjectstore_getAll.any.html (#39276)
    • PASS [expected FAIL] subtest: Get all values with transaction.commit()
  • OK /IndexedDB/idbobjectstore_getAll.any.worker.html (#39400)
    • PASS [expected FAIL] subtest: Get all values with transaction.commit()
  • OK /IndexedDB/idbrequest-onupgradeneeded.any.html (#38895)
    • PASS [expected FAIL] subtest: transaction oncomplete ordering relative to open request onsuccess
  • OK /IndexedDB/idbrequest-onupgradeneeded.any.worker.html (#38971)
    • PASS [expected FAIL] subtest: transaction oncomplete ordering relative to open request onsuccess
  • OK /IndexedDB/key-conversion-exceptions.any.html (#39305)
    • FAIL [expected PASS] subtest: IDBCursor continue() method with throwing/invalid keys

      assert_throws_exactly: key conversion with throwing getter should rethrow function "() => {
            receiver[method](key);
          }" threw object "TypeError: receiver[method] is not a function" but we expected it to throw object "getter: throwing from getter"
      

    • FAIL [expected PASS] subtest: IDBCursor update() method with throwing/invalid keys

      assert_throws_exactly: throwing getter should rethrow during clone function "() => {
            cursor.update(value);
          }" threw object "TypeError: cursor.update is not a function" but we expected it to throw object "getter: throwing from getter"
      

  • OK /IndexedDB/key-conversion-exceptions.any.worker.html (#39284)
    • FAIL [expected PASS] subtest: IDBCursor continue() method with throwing/invalid keys

      assert_throws_exactly: key conversion with throwing getter should rethrow function "() => {
            receiver[method](key);
          }" threw object "TypeError: receiver[method] is not a function" but we expected it to throw object "getter: throwing from getter"
      

    • FAIL [expected PASS] subtest: IDBCursor update() method with throwing/invalid keys

      assert_throws_exactly: throwing getter should rethrow during clone function "() => {
            cursor.update(value);
          }" threw object "TypeError: cursor.update is not a function" but we expected it to throw object "getter: throwing from getter"
      

  • FAIL [expected PASS] /_mozilla/mozilla/sslfail.html (#10760)
  • TIMEOUT [expected OK] /_mozilla/mozilla/window_resize_event.html (#36741)
    • TIMEOUT [expected PASS] subtest: Popup onresize event fires after resizeTo

      Test timed out
      

  • OK /content-security-policy/frame-ancestors/frame-ancestors-path-ignored.window.html (#36468)
    • FAIL [expected PASS] subtest: A 'frame-ancestors' CSP directive with a URL that includes a path should be ignored.

      assert_unreached: The IFrame should have been blocked (or cross-origin). It wasn't. Reached unreachable code
      

  • OK /css/css-cascade/layer-font-face-override.html (#35935)
    • PASS [expected FAIL] subtest: @font-face override update with appended sheet 1
    • PASS [expected FAIL] subtest: @font-face override update with appended sheet 2
  • OK /custom-elements/form-associated/ElementInternals-setFormValue.html (#29174)
    • PASS [expected FAIL] subtest: Single value - empty name exists
    • PASS [expected FAIL] subtest: Single value - Non-empty name exists
  • OK /html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/a-click.html (#28697)
    • FAIL [expected PASS] subtest: aElement.click() before the load event must NOT replace

      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)&code=%0A%20%20%20%20const%20a%20%3D%20document.createElement(%22a%22)%3B%0A%20%20%20%20a.href%20%3D%20%22%2Fcommon%2Fblank.html%3Fthereplacement%22%3B%0A%20%20%20%20document.currentScript.before(a)%3B%0A%20%20%20%20a.click()%3B%0A%20%20"
      

  • OK /html/browsers/history/the-history-interface/traverse_the_history_4.html (#21383)
    • FAIL [expected PASS] subtest: Multiple history traversals, last would be aborted

      assert_array_equals: Pages opened during history navigation expected property 1 to be 5 but got 3 (expected array [6, 5] got [6, 3])
      

  • OK /html/browsers/history/the-history-interface/traverse_the_history_5.html (#21383)
    • FAIL [expected PASS] subtest: Multiple history traversals, last would be aborted

      assert_array_equals: Pages opened during history navigation expected property 1 to be 5 but got 3 (expected array [6, 5] got [6, 3])
      

  • OK /html/browsers/windows/browsing-context-names/duplicate-name-order.html (#34623)
    • PASS [expected FAIL] subtest: Duplicate name lookup order
  • TIMEOUT /html/interaction/focus/the-autofocus-attribute/supported-elements.html (#24145)
    • TIMEOUT [expected PASS] subtest: Non-HTMLElement should not support autofocus

      Test timed out
      

    • NOTRUN [expected FAIL] subtest: Host element with delegatesFocus should support autofocus
    • NOTRUN [expected FAIL] subtest: Host element with delegatesFocus including no focusable descendants should be skipped
  • TIMEOUT /html/semantics/embedded-content/media-elements/autoplay-default-feature-policy.https.sub.html (#41193)
    • TIMEOUT [expected PASS] subtest: Default "autoplay" feature policy ["self"] allows same-origin iframes.

      Test timed out
      

  • OK /html/semantics/forms/form-submission-0/multipart-formdata.window.html (#28725)
    • PASS [expected FAIL] subtest: multipart/form-data: 0x00 in value (formdata event)
    • PASS [expected FAIL] subtest: multipart/form-data: \n in value (formdata event)
  • OK /html/semantics/forms/form-submission-0/text-plain.window.html (#28687)
    • FAIL [expected PASS] subtest: text/plain: Basic File test (normal form)

      assert_equals: expected "basic=file-test.txt\r\n" but got ""
      

  • OK /html/semantics/forms/form-submission-0/urlencoded2.window.html (#28687)
    • FAIL [expected PASS] subtest: application/x-www-form-urlencoded: Basic File test (normal form)

      assert_equals: expected "basic=file-test.txt" but got ""
      

    • PASS [expected FAIL] subtest: application/x-www-form-urlencoded: Basic File test (formdata event)
  • OK /navigation-timing/test-navigation-type-reload.html (#33334)
    • PASS [expected FAIL] subtest: Reload domComplete > Original domComplete
    • FAIL [expected PASS] subtest: Reload domContentLoadedEventEnd > Original domContentLoadedEventEnd

      assert_true: Reload domContentLoadedEventEnd > Original domContentLoadedEventEnd expected true got false
      

    • PASS [expected FAIL] subtest: Reload domContentLoadedEventStart > Original domContentLoadedEventStart
    • PASS [expected FAIL] subtest: Reload fetchStart > Original fetchStart
    • PASS [expected FAIL] subtest: Reload loadEventEnd > Original loadEventEnd
    • PASS [expected FAIL] subtest: Reload loadEventStart > Original loadEventStart
  • OK /service-workers/service-worker/fetch-event.https.html (#36234)
    • PASS [expected FAIL] subtest: Service Worker falls back to network in fetch event with POST form
  • OK [expected TIMEOUT] /trusted-types/trusted-types-navigation.html?06-10 (#37920)
    • PASS [expected TIMEOUT] subtest: Navigate a frame via anchor with javascript:-urls w/ default policy in report-only mode.
    • FAIL [expected NOTRUN] subtest: Navigate a window via anchor with javascript:-urls w/ a default policy throwing an exception in enforcing mode.

      promise_test: Unhandled rejection with value: "Unexpected message received: \"No securitypolicyviolation reported!\""
      

    • FAIL [expected NOTRUN] subtest: Navigate a window via anchor with javascript:-urls w/ a default policy throwing an exception in report-only mode.

      promise_test: Unhandled rejection with value: "Unexpected message received: \"No securitypolicyviolation reported!\""
      

  • TIMEOUT /trusted-types/trusted-types-navigation.html?31-35 (#38034)
    • TIMEOUT [expected PASS] subtest: Navigate a frame via form-submission with javascript:-urls in report-only mode.

      Test timed out
      

    • NOTRUN [expected TIMEOUT] subtest: Navigate a frame via form-submission with javascript:-urls w/ default policy in report-only mode.
Stable unexpected results (2)
  • OK /fetch/api/idlharness.https.any.html
    • PASS [expected FAIL] subtest: Request interface: attribute keepalive
    • PASS [expected FAIL] subtest: Request interface: new Request('about:blank') must inherit property "keepalive" with the proper type
  • OK /fetch/api/idlharness.https.any.worker.html
    • PASS [expected FAIL] subtest: Request interface: attribute keepalive
    • PASS [expected FAIL] subtest: Request interface: new Request('about:blank') must inherit property "keepalive" with the proper type

@github-actions

Copy link
Copy Markdown

⚠️ Try run (#20300918845) failed.

@TimvdLippe
TimvdLippe force-pushed the implement-fetch-later-keep-alive branch from 59ae739 to 7fac501 Compare December 17, 2025 13:16

@gterzian gterzian left a comment •

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 it's fine to add the interface only, although most value will come only later when the underlying mechanisms are implemented.

There is one change to the business logic that appears wrong to me, mostly because the existing code seems to conflate the terminate and abort concepts.

The flag is then passed into a canceller. While we could make canceller optional, in many cases it isn't and would require a whole lot more changes. To follow the spec more closely, opted to put the keep_alive flag on the canceller as well.

My guess is that you don't wan to add the flag to the canceller, because even keep alive fetches can be cancelled. Rather, the difference is that keep alive fetches are not terminated when the fetch group is terminated, which enables deferred fetches. But that is a separate concept from fetch aborting.

I think the problem may be that the existing code uses a fetch canceller both for aborting and other cancelling that are closer to the spec concept of termination.

The broader solution, if you want to support keep alive fetches, is to look into implementing fetch groups and disentangling fetch aborting from terminating a fetch group.

Comment thread components/script/fetch.rs Outdated
// is unset and keepalive is false, terminate record’s controller.
if self.keep_alive {
return;
}

@gterzian gterzian Dec 17, 2025 •

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.

This doesn't seem to be correct, because even keep alive fetches can be aborted, see "Run these steps, but abort when fetchParams is canceled:" of https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch

As I understand it, this method is called as part of the fetch abort flow:

pub(crate) fn abort_fetch(

So the spec link is for "terminate", which is not the same thing.

I think this method should instead follow https://fetch.spec.whatwg.org/#fetch-controller-abort.

Regarding terminating a fetch group, I don't think we implement fetch group yets, and actually from the spec it's not clear to me when a fetch group is terminated. The spec just says what to do when it happens, but not what triggers it: see https://fetch.spec.whatwg.org/#concept-fetch-group-terminate I'm guessing a fetch group should terminate when the associated environment goes away(navigated away).

So keep alive is something to handle among others at

// Step 8.10 If contentLength is non-null and httpRequest’s keepalive is true, then:

And it is also a way to run deferred fetches, which happen after the fetch group has terminated.

But it is important to avoid conflating fetch aborting/cancelling with terminating a fetch group.

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, I had thought about that as well. When we abort a fetch, we call canceller.cancel(). Therefore, we should add this check in the Drop implementation meaning that the .cancel() will go through?

The specification doesn't list it indeed, it leaves it up to user agents to figure out when to call. However, we already implement a similar part in document_loader, hence I think that's the most logical place for us (and passes WPT tests).

Note that tests/wpt/tests/fetch/fetch-later/send-on-discard/not-send-after-abort.https.window.js tests this. We already pass it, since we don't implement iframe destroying correctly. That will be fixed in the follow-up (#41346), hence you don't see test changes in this PR. However, I verified that it works correctly when both pieces of the puzzle are correctly working.

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 I realize that the diff for document_loader isn't shown as I implemented that in the previous PR. The logic for "the fetch group" is here:

/// <https://fetch.spec.whatwg.org/#concept-fetch-group-terminate>
pub(crate) fn cancel_all_loads(&mut self) -> bool {
// Step 1. For each fetch record record of fetchGroup’s fetch records,
// if record’s controller is non-null and record’s request’s done flag
// is unset and keepalive is false, terminate record’s controller.
//
// Implemented in [`FetchCanceller::cancel`] which runs when these cancellers are dropped.
let canceled_any = !self.cancellers.is_empty();
self.cancellers.clear();
// Step 2. Process deferred fetches for fetchGroup.
for deferred_fetch in self.deferred_fetches.drain(..) {
deferred_fetch.lock().unwrap().process();
}
canceled_any
}

@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 Dec 17, 2025
@TimvdLippe
TimvdLippe force-pushed the implement-fetch-later-keep-alive branch from 7fac501 to 284563f Compare December 17, 2025 15:15
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 17, 2025
@TimvdLippe
TimvdLippe requested a review from gterzian December 17, 2025 15:21

@gterzian gterzian left a comment

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.

LGTM with one comment: I think the use of keep-alive in the conditional to prevent cancelling is best removed from this PR, and added back in a follow-up that would also fix the structure.

if self.keep_alive {
return;
}
self.cancel()

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 don't think using drop is a good idea, because it makes it unclear when the method is called, for example it will be called in case of panic as well. Also, the cancel method can panic itself, and that should be avoided in a drop implementation see https://doc.rust-lang.org/std/ops/trait.Drop.html#panics.

Instead you could have two methods: terminate and abort, both of which can call cancel, and where terminate is not called(or does not call cancel) on the canceller when the equivalent of a fetch group terminates, if the fetch is keep-alive. cancel_all_loads would then call terminate explicitly(or not call it if keep-alive).

So in this PR I would just remove the entire self.keep_alive conditional, and in a follow-up(s) work on implementing the keep-alive functionality as it relates to termination.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Dec 18, 2025
This implements the required plumbing for the keep-alive
flag on requests. The flag already exists on the request
object, but now also exists on the builder itself.

The flag is then passed into a canceller. While we could
make canceller optional, in many cases it isn't and would
require a whole lot more changes. To follow the spec more
closely, opted to put the keep_alive flag on the canceller
as well.

Note that this doesn't pass any extra fetch-later tests
since we are not correctly unloading iframe documents.
That will be fixed in a follow-up PR.

Part of servo#41230

Signed-off-by: Tim van der Lippe <[email protected]>
@TimvdLippe
TimvdLippe force-pushed the implement-fetch-later-keep-alive branch from 284563f to 4d81075 Compare December 18, 2025 19:43
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 18, 2025
@TimvdLippe
TimvdLippe enabled auto-merge December 18, 2025 19:43
@TimvdLippe
TimvdLippe added this pull request to the merge queue Dec 18, 2025
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 18, 2025
Merged via the queue into servo:main with commit 3ac02bc Dec 18, 2025
@TimvdLippe
TimvdLippe deleted the implement-fetch-later-keep-alive branch December 18, 2025 20:25
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 18, 2025
TimvdLippe added a commit to TimvdLippe/servo that referenced this pull request Dec 18, 2025
Instead, we now explicitly call `.terminate()` and
introduce relevant methods to FetchCanceller.

Follow-up from review in servo#41345

Signed-off-by: Tim van der Lippe <[email protected]>
TimvdLippe added a commit to TimvdLippe/servo that referenced this pull request Dec 18, 2025
Instead, we now explicitly call `.terminate()` and
introduce relevant methods to FetchCanceller.

Follow-up from review in servo#41345

Signed-off-by: Tim van der Lippe <[email protected]>
github-merge-queue Bot pushed a commit that referenced this pull request Dec 19, 2025
Instead, we now explicitly call `.terminate()` and introduce relevant
methods to FetchCanceller.

Follow-up from review in #41345

---------

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

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants