Fix ConcurrentModificationException in RemoteRecorder

This commit is contained in:
0xb00bface 2021-08-08 19:39:05 +02:00
parent e3f42ffc1c
commit 7218ed04fb
1 changed files with 15 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantLock;
import org.json.JSONObject;
import org.slf4j.Logger;
@ -70,6 +71,7 @@ public class RemoteRecorder implements Recorder {
private List<Model> models = Collections.emptyList();
private List<Model> onlineModels = Collections.emptyList();
private List<Recording> recordings = Collections.emptyList();
private ReentrantLock modelGroupLock = new ReentrantLock();
private Set<ModelGroup> modelGroups = new HashSet<>();
private List<Site> sites;
private long spaceTotal = -1;
@ -202,8 +204,13 @@ public class RemoteRecorder implements Recorder {
throw new IOException("Server returned error " + resp.status + " " + resp.msg);
}
modelGroups.clear();
modelGroups.addAll(resp.groups);
modelGroupLock.lock();
try {
modelGroups.clear();
modelGroups.addAll(resp.groups);
} finally {
modelGroupLock.unlock();
}
}
private void addHmacIfNeeded(String msg, Builder builder) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
@ -691,7 +698,12 @@ public class RemoteRecorder implements Recorder {
@Override
public Set<ModelGroup> getModelGroups() {
return new HashSet<>(modelGroups);
modelGroupLock.lock();
try {
return new HashSet<>(modelGroups);
} finally {
modelGroupLock.unlock();
}
}
@Override