1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 569123 - Race condition on AbstractMIControl.fRxCommands

This change adds synchronization to iterating over the map
AbstractMIControl.fRxCommands during
AbstractMIControl.cancelRxCommands(). This prevents potential
ConcurrentModificationExceptions when elements are added or removed to
the map in parallel during e.g. AbstractMIControl.TxThread.run() loop.

The change also removes superfluous synchronization for method
AbstractMIControl.cancelRxCommands().

Change-Id: Id7c01b3057e522cce324a002dce54f0fabe02623
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
This commit is contained in:
Simeon Andreev 2020-11-24 16:41:37 +01:00 committed by Jonah Graham
parent 293998da18
commit 7881736c68

View file

@ -30,6 +30,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -327,14 +328,18 @@ public abstract class AbstractMIControl extends AbstractDsfService implements IM
fTxCommands.add(fTerminatorHandle);
}
private synchronized void cancelRxCommands() {
for (CommandHandle commandHandle : fRxCommands.values()) {
private void cancelRxCommands() {
Map<Integer, CommandHandle> rxCommandsCopy;
synchronized (fRxCommands) {
rxCommandsCopy = new LinkedHashMap<>(fRxCommands);
fRxCommands.clear();
}
for (CommandHandle commandHandle : rxCommandsCopy.values()) {
if (commandHandle.getRequestMonitor() == null)
continue;
commandHandle.getRequestMonitor().setStatus(genStatus("Connection is shut down")); //$NON-NLS-1$
commandHandle.getRequestMonitor().done();
}
fRxCommands.clear();
}
/**