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.
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
Use
ReentrantLock
instead ofsynchronized
inDeserializerCache
to avoid deadlock on pinning #4430Use
ReentrantLock
instead ofsynchronized
inDeserializerCache
to avoid deadlock on pinning #4430Changes from 2 commits
48124cd
2668e5f
43a2e8a
d512683
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is not 100% correct - If you have 2 deserializer instances with the same _customFormat instance then synchronizing it will prevent concurrent use of that _customFormat instance - your lock would not work properly in that case.
It is sort of annoying that Java never made DateFormat thread-safe. We could look into finding thread-safe alternatives - or adding a thread-safe class of our own that wraps DataFormat but that uses a locking mechanism to control access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't researched this but I suspect we could find some
java.time
API to do date/time formatting that is thread safe - and therefore not need locking here at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, the existing
DateFormat
should be replaced with ajava.time.format.DateTimeFormatter
which is immutable and thread-safe and at that point this synchronization could be of course totally removed. However I guess that this could be addressed with a different pull request, immediately after this will be merged.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure replacement would work, unfortunately, since we are talking about support for
java.util.Date
/java.util.Calendar
; and if I remember correctly, format Strings used withSimpleDateFormat
are different from those used with Java 8 date/time (and Joda).So the better fix for users is to upgrade from java.util types to java.time.
So while I agree with all the ugliness of java.util world, I am not sure spending time on better support there is worth the effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this Date code is not on critical path - users can avoid it using java.time classes instead of java.util Data/Calendar
so this could be left alone - and maybe tackled later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem as I described for DateDeserializers - what if
JavaType _defaultImpl
instance is used by more than 1 TypeDeserializerBase instance. This set of refactors seem really dangerous to me. I hate the idea of hacking like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this is wrong. In my opinion the
ReentrantLock
should be moved inside theJavaType
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
JavaType
would be the place: locking here is specifically to try to avoid duplicate lookups for deserializer used for "default type" (of given polymorphic base type).However. Since this is not done for correctness but as (possibly misguided?) performance optimization, maybe even use of basic
AtomicReference
would work (accepting possible race condition).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this should never cause issues? There's no I/O operations within
Map
(LRUMap
),TypeKey
is stateless.In fact... I don't think synchronization should be needed at all here:
LRUMap
states:so could it be this is legacy, pre-2.14 locking, that was just left for no good reason...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading through the code, this may not be as simple as I thought (see #4442): I think
synchronized
actually has secondary purpose to act as monitor for resolution of cyclic dependencies for POJO serializers (BeanSerializer
). And if so it cannot really be safely removed (but is also a big potential performance concern at same time).