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

Avoid race conditions when setting RCTNetworkTask status #28962

Closed
wants to merge 2 commits into from

Conversation

pxpeterxu
Copy link
Contributor

@pxpeterxu pxpeterxu commented May 25, 2020

Summary

While using a library that made a call to React Native's "loadImageWithURLRequest", I noticed that once in every 5 calls, we'd get the following error message:

Task orphaned for request <NSMutableURLRequest: [[SOME_HEX_CODE]]> { URL: [[IMG_URL]] }

This was despite everything working just fine: the image load would call the success callback without any problems.

For more context: loadImageWithURLRequest was called from a thread that had a lower priority than default.

After investigating this by stepping through with XCode, what was happening was that:

  1. Thread 1: loadImageWithURLRequest would call [task start] on a NetworkTask to send the request for the image
  2. Thread 1: [task start] would send the request using the corresponding handler
  3. In my case, I was using a ph:// photo/asset library URL, which gets handled by RCTAssetsLibraryRequestHandler. In this case, even though the request was sent from a background thread, the result seems to always be returned on the main thread
  4. Thread 2: After completing the request:
  5. Thread 1: Some time later, the thread resumes, and sets the status to RCTNetworkTaskInProgress, even though it's actually already finished!
  6. Thread 1: Later on, when the ImageLoader iterates through the network tasks again, it finds the odd case where there's no requestToken yet it's marked as in progress.

This may address some, but not all causes of #12152

Changelog

[iOS] [Fixed] - Fix race conditions in NetworkTask that caused ImageLoader to report Task Orphaned

Test Plan

Tested using RNTester; also, verified that the warning messages for "Task orphaned" no longer appear in test app

@facebook-github-bot
Copy link
Contributor

Hi @pxpeterxu!

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 at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@react-native-bot react-native-bot added Bug Platform: iOS iOS applications. labels May 25, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 25, 2020
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@analysis-bot
Copy link

analysis-bot commented May 25, 2020

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 6,764,741 0
android hermes armeabi-v7a 6,432,395 0
android hermes x86 7,152,590 0
android hermes x86_64 7,042,493 0
android jsc arm64-v8a 8,936,131 0
android jsc armeabi-v7a 8,596,166 0
android jsc x86 8,767,068 0
android jsc x86_64 9,342,599 0

Base commit: 8d613c6

@analysis-bot
Copy link

analysis-bot commented May 25, 2020

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 8d613c6

@github-actions
Copy link

github-actions bot commented May 6, 2023

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 6, 2023
@github-actions
Copy link

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants