-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix race condition when ShareableHandle is accessed on multiple threads #5759
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thanks @tjzel, this must have been hard to track down! |
tjzel
force-pushed
the
@tjzel/iterative-crash-debug
branch
from
March 4, 2024 12:36
18135d8
to
cb91e6c
Compare
@tjzel I was looking into linked issue and it seemed that the problem was occurring only in newest release. Could you please track down and link here the exact PR causing the bug? |
@Latropos, it's been occurring since 3.7.0. |
piaskowyk
reviewed
Mar 6, 2024
piaskowyk
approved these changes
Mar 6, 2024
tomekzaw
approved these changes
Mar 6, 2024
6 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5660, a regression introduced in #4300.
The aforementioned race condition happens this way:
ShareableHandle
underneath (e.g. a shared value) is created.ShareableHandle
get called on the UI thread.initializer_
has been nulled and causes memory access issues.It's difficult to change the whole flow of locking to prevent such scenarios. Therefore we won't null the
initializer_
object anymore. However, this won't fix the problem of potential double initialization. Luckily, the code ofvalueUnpacker
already prevents that with its shareable handle cache and the fact that runtime operations must be sequential.Test plan
Run the following race condition reproduction made - you should re-run the app several times (probably up to 20ish) since it's most likely to happen when the app starts. It's also more likely to happen on Android simulators (at least for me).
Test code
You can do the following to see that double initialization happens still, but all is well 🚰.
Big thanks to @piaskowyk for the debugging help 🚀