-
Notifications
You must be signed in to change notification settings - Fork 4.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 for concurrent serialization of recursive type #767
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
This commit breaks a couple of tests, so please don't consider this final. Pushed to have a starting point. |
My guess is that the best fix will be to change FutureTypeAdapter to look up the type adapter in Gson when it suffers a miss. |
@swankjesse I think that would be quite an elaborate fix since you would have to synchronize between the two threads. Add a latch so that the thread that misses can wait on the one that sets the delegate. |
This race happens when two or more threads try to serialize the same recursive type for the first time at the same time. The fix makes sure that TypeAdapter instances are not cached in the instance cache until all FutureTypeAdapters in a re-entrant call to getAdapter() have their delegates set. Also see: #764
Changed the fix to overwrite the future type adapters with the real one in the threadCalls map. This leads to the same result as before, where the newly built types are only externalized to other threads once the last one has been created, unlike the situation before this fix. |
The CLA is taken care of. See the vmware-google-contributors Google Group. @swankjesse This is ready to merge, if this is the way you want to go for the fix (it's the most straightforward way to fix it in my opinion, by not leaking any adapters into the cache before the whole tree is traversed). |
Hi there, I was looking #764 and came this PR. Thanks, |
Ping. Any chance of this getting merged in? |
Hello, The fix looks good, any particular reason to delay merging? |
Thanks a lot for you work on this! This has now be fixed by #1832, but thank you nonetheless! |
This race happens when two or more threads try to serialize the same recursive type for the first time at the same time.
The fix makes sure that TypeAdapter instances are not cached in the instance cache until all FutureTypeAdapters in a re-entrant call to getAdapter() have their delegates set.
Also see: #764