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

Execute cancel block in the _URLRequestQueue #10280

Closed
wants to merge 2 commits into from

Conversation

sooth-sayer
Copy link
Contributor

Fixes #10274

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @skatpgusskat and @javache to be potential reviewers.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@ide
Copy link
Contributor

ide commented Oct 10, 2016

@javache this seems roughly right -- we want the cancellation block, or at least parts of it, to run on the URL request queue. I'm not sure this specific solution is the best way to go about things, though, since the cancellation block modified in this PR is sometimes wrapped in other cancellation blocks that we might want to run on the URL request queue too.

With this PR: other methods' cancellation blocks invoke _loadImageOrDataWithURLRequest's cancellation block, which dispatches to the URL request queue and runs more cancellation code.

What I'm thinking: other methods' (specifically public methods) cancellation blocks dispatch to the URL request queue and invoke _loadImageOrDataWithURLRequest's cancellation block, which doesn't do a dispatch (maybe it assets which queue it is running on). That way all cancellation code consistently runs on the URL request queue, and we're not nesting dispatch_async calls either.

@sooth-sayer
Copy link
Contributor Author

@ide In some cases (https://github.com/facebook/react-native/blob/master/Libraries/Image/RCTImageLoader.m#L342) we must not call cancellation block returned by _loadImageOrDataWithURLRequest on the URL request queue. So, i think that _loadImageOrDataWithURLRequest is responsible for dispatching cancellation block to the appropriate queue.

@christopherdro
Copy link
Contributor

Does this commit possible address the issue?
1a62b66

@gre
Copy link
Contributor

gre commented Oct 10, 2016

@christopherdro maybe someone else can confirm this, but I've actually been able to still reliably trigger the error even on current master including the commit you mentioned. More precisely, after 1a62b66 I was still able to trigger the bug, but I noticed it was a bit harder to trigger. So my guess is this commit was incomplete on covering all breaking cases.

After applying this PR I can't anymore trigger the bug, so thanks to @sooth-sayer.

cancelLoad = nil;
}
OSAtomicOr32Barrier(1, &cancelled);
dispatch_async(_URLRequestQueue, ^{
Copy link
Member

@javache javache Oct 11, 2016

Choose a reason for hiding this comment

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

Looks reasonable but could you structure it like this? Also, you'll need to use weakSelf / strongSelf to access _URLRequestQueue? Right now this will retain self.

return ^{
  typeof(self) strongSelf = weakSelf;
  if (strongSelf && !cancelled) {
    dispatch_async(strongSelf->_URLRequestQueue, ^{
      if (cancelLoad) {
        cancelLoad();
        cancelLoad = nil;
     }
  });
  OSAtomicOr32Barrier(1, &cancelled);
};

@javache
Copy link
Member

javache commented Oct 11, 2016

Even better would be to put this dispatch inside the block that does the actual cancelling.

@facebook-github-bot
Copy link
Contributor

@sooth-sayer updated the pull request - view changes

@sooth-sayer
Copy link
Contributor Author

@javache Do you mean that we should put dispatch inside

if (cancelLoad) { 
  ...
} 

?

@javache
Copy link
Member

javache commented Oct 11, 2016

I've got a fix up for this internally which includes your changes. I'll try land it later today, thanks!

@sooth-sayer
Copy link
Contributor Author

@javache Ok, 👍

@avilyn
Copy link

avilyn commented Oct 11, 2016

@javache Are you able to estimate when a version will be released that includes this fix? Is that what you meant by "land it later today" above?

@ide
Copy link
Contributor

ide commented Oct 11, 2016

@avilyn if it lands today or in the next few days it will go out with 0.37 (ETA 4 weeks) and we would probably cherry pick it back into 0.36 (ETA 2 weeks, currently in RC so you can use it now).

facebook-github-bot pushed a commit that referenced this pull request Oct 11, 2016
Summary: Fix suggested by sooth-sayer (#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
@avilyn
Copy link

avilyn commented Oct 11, 2016

@ide Perfect, thank you.

@javache
Copy link
Member

javache commented Oct 11, 2016

Landed in 26be005 I'll ask for it to be picked 0.36 too.

@javache javache closed this Oct 11, 2016
pfeiffer pushed a commit to pfeiffer/react-native that referenced this pull request Oct 12, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
ide pushed a commit that referenced this pull request Oct 13, 2016
Summary: Fix suggested by sooth-sayer (#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
mikelambert pushed a commit to mikelambert/react-native that referenced this pull request Oct 13, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
oblador pushed a commit to oblador/react-native that referenced this pull request Oct 13, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
ide pushed a commit to expo/react-native that referenced this pull request Oct 26, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
adba pushed a commit to adba/react-native that referenced this pull request Oct 27, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
ide pushed a commit to expo/react-native that referenced this pull request Oct 27, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
rigdern pushed a commit to rigdern/react-native that referenced this pull request Nov 3, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
(cherry picked from commit 64dd140)
huitsing pushed a commit to huitsing/react-native that referenced this pull request Dec 5, 2016
Summary: Fix suggested by sooth-sayer (facebook#10280)

Reviewed By: mmmulani

Differential Revision: D4001618

fbshipit-source-id: cc28d19d02a29b62d2bdbddcd30f94b1c1bcfd76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants