-
Notifications
You must be signed in to change notification settings - Fork 82
Fix MyClassLoader idempotency - issue #49 #50
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
Merged
cowtowncoder
merged 8 commits into
FasterXML:2.9
from
jbagdis:bugfix/myclassloader-idempotency
Feb 16, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
22296ab
add failing tests for MyClassLoader idempotency issue
jbagdis f37d4b8
fix MyClassLoader idempotency issue
jbagdis ff6add7
add failing tests for race condition in MyClassLoader when tryToUsePa…
jbagdis 2c68466
fix race condition in MyClassLoader when tryToUseParent is true
jbagdis 03db4c1
add logging for exceptions in calls against parent ClassLoader
jbagdis f4806f9
ensure new class is resolved by the loader than defined it
jbagdis 39af2fc
use a lock internal to MyClassLoader for synchronization of calls to …
jbagdis a609ce1
use concatenation instead of String.format
jbagdis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Oops, something went wrong.
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.
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.
Do we need a corresponding
parentParallelLockMap.remove(key)
at the end of the critical section before releasing this lock to avoid this map growing unbounded?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 it will work to simply expire entries from the map when the lock is released. Consider this sequence of operations contending for a lock for the same class name/loader pair (i.e. with the same map key: 'key'), beginning with an empty map:
[Thread A]: requests lock object for 'key'; map contains no entry for 'key' so Object-1 is created and added to map, then returned.
[Thread A]: attempts to acquire lock for Object-1; succeeds immediately.
[Thread B]: requests lock object for 'key'; receives Object-1 from map.
[Thread B]: attempts to acquire lock for Object-1; blocks.
[Thread A]: completes its work in the synchronized region and then (in either order) releases the lock on Object-1 and removes the
'key' -> Object-1
mapping from the map.[Thread B]: immediately acquires lock for Object-1 and unblocks.
[Thread C]: requests lock object for 'key'; map contains no entry for 'key' so Object-2 is created and added to map, then returned.
[Thread C]: attempts to acquire lock for Object-2; succeeds immediately.
Now, Thread B and Thread C are both in the synchronized region together for what should be the same lock.
A Guava (or Caffeine)
Cache
with weak values would do the trick, but I doubt it's worth adding that dependency. For what it's worth, though, this is the same implementation as used byClassLoader
itself. Its lock map also grows without bound (but, since it only ever gains one entry per loaded class it can't really grow that big)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.
Good call @jbagdis , having a corresponding remove does allow for the race condition you mentioned.