Skip to content
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

Handle case of refreshed cache entry still receiving data #21079

Merged
merged 1 commit into from Jun 23, 2018

Conversation

@gterzian
Copy link
Member

gterzian commented Jun 22, 2018

When refreshing cached entries, handle the case the the entry is still "receiving"...


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #20802 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Jun 22, 2018

Heads up! This PR modifies the following files:

@highfive
Copy link

highfive commented Jun 22, 2018

warning Warning warning

  • These commits modify net code, but no tests are modified. Please consider adding a test!
@highfive highfive assigned jdm and unassigned avadacatavra Jun 22, 2018
@gterzian
Copy link
Member Author

gterzian commented Jun 22, 2018

r? @jdm
Manual testing with ./mach run -d --pref dom.mutation_observer.enabled https://aframe.io/examples/showcase/a-blast/(and a few page reloads) seems to indicate the problem has been fixed...

@gterzian gterzian force-pushed the gterzian:fix_cache_refresh branch 3 times, most recently from 87a52ae to 313506e Jun 22, 2018
@gterzian gterzian changed the title handle case of refreshed cache entry still receiving data Handle case of refreshed cache entry still receiving data Jun 22, 2018
@gterzian
Copy link
Member Author

gterzian commented Jun 22, 2018

I just realized we probably don't want to keep the done_chan created by the fetch worker, since that is related to the 304 response, not the refreshed cached response...

Looking into it and will update this shortly...

@gterzian gterzian force-pushed the gterzian:fix_cache_refresh branch from 313506e to 31c5be5 Jun 22, 2018
@gterzian
Copy link
Member Author

gterzian commented Jun 22, 2018

Ok, this seems to do the trick.

So the problem is the DoneChannel will have been set to Some(..) by the network fetch, but that is the channel related to the 304 response, not the cached resource that is to be refreshed.

In the case that the cached resource is actually still receiving data(from another fetch worker), then we set the channel to a new Some(..), and we wait on it until the data has been received(like is done 'normally' when the cache constructs a resource that is still receiving bytes).

Once the response is 'done', we set the channel back to None...

If the cached resource that is being refreshed is already done or empty, we set the channel to None immediately.

Ready for review.

@jdm
Copy link
Member

jdm commented Jun 22, 2018

@gterzian Is it possible to write a unit test or web platform test for this behaviour?

ResponseBody::Receiving(..) => {
let (done_sender, done_receiver) = channel();
*done_chan = Some((done_sender.clone(), done_receiver));
cached_resource.awaiting_body.lock().unwrap().push(done_sender);

This comment has been minimized.

Copy link
@jdm

jdm Jun 22, 2018

Member

Is there a risk of deadlock here while the cached_resource.body lock is held? Would it be safer to do something like:

let in_progress_channel = match *cached_resource.body.lock().unwrap() {
    ResponseBody::Receiving(..) => Some(channel())
    ResponseBody::Empty | ResponseBody::Done(..) => None
};
match in_progress_channel {
    Some((done_sender, done_receiver)) => {
        cached_resource.awaiting_body.lock().unwrap().push(done_sender.clone());
        *done_chan = Some((done_sender, done_receiver));
    }
    None => *done_chan = None,
}
@gterzian gterzian force-pushed the gterzian:fix_cache_refresh branch from 31c5be5 to f7d3a18 Jun 23, 2018
@gterzian gterzian force-pushed the gterzian:fix_cache_refresh branch 6 times, most recently from 7feaa36 to e879ae6 Jun 23, 2018
@gterzian gterzian force-pushed the gterzian:fix_cache_refresh branch from e879ae6 to 96c1242 Jun 23, 2018
@gterzian
Copy link
Member Author

gterzian commented Jun 23, 2018

@jdm I ended up adding a fairly focused unit-test, mainly because I wasn't able to reproduce the error with either a wpt or a more integration-like fetch test. I'm fairly satisfied because the unit-test did initially fail, and it covers the logical error...

@jdm
Copy link
Member

jdm commented Jun 23, 2018

@bors-servo r+
Thanks for adding that!

@bors-servo
Copy link
Contributor

bors-servo commented Jun 23, 2018

📌 Commit 96c1242 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jun 23, 2018

Testing commit 96c1242 with merge d70e131...

bors-servo added a commit that referenced this pull request Jun 23, 2018
Handle case of refreshed cache entry still receiving data

<!-- Please describe your changes on the following line: -->

When refreshing cached entries, handle the case the the entry is still "receiving"...

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #20802 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21079)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 23, 2018

💔 Test failed - mac-rel-wpt1

@CYBAI
Copy link
Collaborator

CYBAI commented Jun 23, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jun 23, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jun 23, 2018

@bors-servo bors-servo merged commit 96c1242 into servo:master Jun 23, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@gterzian gterzian deleted the gterzian:fix_cache_refresh branch Jun 24, 2018
@gterzian gterzian restored the gterzian:fix_cache_refresh branch Jun 28, 2018
@gterzian gterzian deleted the gterzian:fix_cache_refresh branch Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.