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
Rare exception during POJO serialization #764
Comments
I'm seeing the same thing. Happens if two or more threads try to serialize the same recursive type for the first time at the same time. Verified this is also an issue with GSON 2.5. |
Here's what I think is happening:
To fix this, the implementation of |
Yeah, yuck. |
Working on a fix... Not overly proud of the following snippet, but I'm using it as a stop gap until there is a new version of GSON is released with a real fix: for (int i = 1;; i++) {
try {
return gson.toJson(obj);
} catch (IllegalStateException e) {
if (e.getMessage() == null) {
if (i >= MAX_SERIALIZATION_ATTEMPTS) {
throw e;
}
// This error may happen when two threads try to serialize a recursive
// type for the very first time concurrently. Type caching logic in GSON
// doesn't deal well with recursive types being generated concurrently.
// Also see: https://github.com/google/gson/issues/764
Thread.yield();
continue;
}
throw e;
}
} |
This error may happen when two threads try to serialize a recursive type for the very first time concurrently. Type caching logic in GSON doesn't deal well with recursive types being generated concurrently. Also see: google/gson#764 Change-Id: I64babcd7f8b690ace59d4948eeeabc13a740b2f1
This error may happen when two threads try to serialize a recursive type for the very first time concurrently. Type caching logic in GSON doesn't deal well with recursive types being generated concurrently. Also see: google/gson#764 Change-Id: I64babcd7f8b690ace59d4948eeeabc13a740b2f1
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: google#764
We don't need multiple implementations anymore, and we'll need to execute complex initialization code to work around a bug in Gson (google/gson#764).
We don't need multiple implementations anymore, and we'll need to execute complex initialization code to work around a bug in Gson (google/gson#764).
We don't need multiple implementations anymore, and we'll need to execute complex initialization code to work around a bug in Gson (google/gson#764).
Same as #625 |
This should be fixed by #1832, which will be available in the next release |
We're seeing what appears to be some sort of concurrency-related bug in our CI system. It occurs very rarely and only when multiple threads are serializing similar objects.
The hierarchy being serialized is as follows:
A
ChildrenList
object is being serialized and dumping the content of the output buffer shows that the error happens in a field of the firstFolder
element of thefolders
field. To be precise, the partial output looks like:A single static Gson instance is shared by multiple threads serializing POJO into HTTP response bodies and is initialized as follows:
Has anyone ever run into a similar issue? Is there anything we can do to get a more helpful stack trace when the error happens?
The text was updated successfully, but these errors were encountered: