Repository navigation
script: Mark fetch-later requests as keep-alive - #41345
Conversation
|
🔨 Triggering try run (#20300918845) for Linux (WPT) |
|
Test results for linux-wpt from try job (#20300918845): Flaky unexpected result (34)
Stable unexpected results that are known to be intermittent (27)
Stable unexpected results (2)
|
|
|
59ae739 to
7fac501
Compare
There was a problem hiding this comment.
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.
| // is unset and keepalive is false, terminate record’s controller. | ||
| if self.keep_alive { | ||
| return; | ||
| } |
There was a problem hiding this comment.
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:
servo/components/script/fetch.rs
Line 464 in 6c030bf
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
servo/components/net/http_loader.rs
Line 1400 in 575b7ab
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
servo/components/script/document_loader.rs
Lines 111 to 126 in 6c030bf
7fac501 to
284563f
Compare
gterzian
left a comment
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
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]>
284563f to
4d81075
Compare
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]>
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]>
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]>
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