Repository navigation
net: Return FetchController from fetch - #49263
TimvdLippe wants to merge 1 commit into
Conversation
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]>
|
🔨 Triggering try run (#40214914470) for Linux (WPT) |
| "Failed to preload".into(), | ||
| )) | ||
| }) | ||
| .unwrap_or(response.clone()); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
I also don't have any ideas yet besides wrapping the response in a Rc. It's unfortunate.
|
Test results for linux-wpt from try job (#40214914470): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (7)
|
|
✨ Try run (#40214914470) succeeded. |
| } | ||
|
|
||
| // Step 11.6. If processResponse is given, then call processResponse with response. | ||
| self.preload_target.process_response_eof(request, response); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>>; |
There was a problem hiding this comment.
Why is this necessary? What code needs to mutate the values inside it?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
…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]>
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