Skip to content

Commit

Permalink
Merge pull request #716 from tadamski/EJBCLIENT-536
Browse files Browse the repository at this point in the history
[EJBCLIENT-536] RemotingEJBDiscoveryProvider: run cancel handlers out…
  • Loading branch information
tadamski committed Jul 16, 2024
2 parents d6638f0 + f7176d6 commit 2c66997
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,19 +591,24 @@ public void addMatch(final ServiceURL serviceURL) {

public void cancel() {
final List<Runnable> cancellers = this.cancellers;
final List<Runnable> cancellersCopy;
synchronized (cancellers) {
/**
/*
In scenario in which the last node performs a cancel operation and discovery fails a retry is
attempted (see phase2 in countdown method above). This triggers opening new connections and,
as a result, adding cancellers, which are being iterated over in this method leading to
ConcurrentModificationException. To avoid this the copy is created.
See https://issues.redhat.com/browse/JBEAP-24568
*/
final List<Runnable> cancellersCopy = new ArrayList<>(cancellers);
for (Runnable canceller : cancellersCopy) {
canceller.run();
}
cancellersCopy = new ArrayList<>(cancellers);
}
/*
* EJBCLIENT-536 - since we are iterating the copy we can safely do it outside synchronized block; running
* the cancellers synchronized may cause deadlocks
*/
for (Runnable canceller : cancellersCopy) {
canceller.run();
}
}

Expand Down

0 comments on commit 2c66997

Please sign in to comment.