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
Address ConcurrentModificationException on ThreadLocalPool #14511
Address ConcurrentModificationException on ThreadLocalPool #14511
Conversation
…ndoned connections in ThreadLocalPool.
@@ -72,7 +72,7 @@ PoolType pool() { | |||
} | |||
|
|||
private final void scanForAbandonedConnections() { | |||
for (PoolAndThread pair : allConnections) { | |||
for (PoolAndThread pair : new ArrayList<>(allConnections)) { |
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 think this may still run into ConcurrentModificationException (when copying to the other list).
A proper solution is to replace the ArrayList
instance used in allConnections
with a CopyOnWriteArrayList
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 - just pushed a small additional commit.
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 used a slightly different approach as I actually did it before seeing your suggestion)
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.
And it's actually still not 100% right..
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.
Nevermind, should be correct as all accesses to this method are exclusive because of the synchronization pattern.
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.
Approved, just need another CI run.
@@ -72,13 +72,19 @@ PoolType pool() { | |||
} | |||
|
|||
private final void scanForAbandonedConnections() { | |||
ArrayList<PoolAndThread> garbage = new ArrayList<>(); | |||
for (PoolAndThread pair : allConnections) { |
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 iteration may still fail if the allConnections list changes
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's locked, it's not going to change at this time.
only a JDK8/JVM test failed, and it was:
That's not related, so let's merge this one. |
Many thanks @nachogiljaldo ! |
Fixes #14510
I tried to keep the solution super-simple since I saw this code might go away real soon, I added a test that reproduces.
IMHO, there should be a 1.11.1 with this change, this seems like a deal breaker for users in that version (I had to move back to 1.10.5.FINAL for example).