Skip to content

Commit d70445c

Browse files
VietND96Copilot
andauthored
Fix review comment as suggestion
Co-authored-by: Copilot <[email protected]>
1 parent 8b1ba6f commit d70445c

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

java/src/org/openqa/selenium/grid/sessionmap/local/LocalSessionMap.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,29 +242,34 @@ public Session remove(SessionId id) {
242242
}
243243

244244
public void batchRemove(Set<SessionId> sessionIds) {
245-
Map<URI, Set<SessionId>> uriToSessionIds = new HashMap<>();
246-
247-
for (SessionId id : sessionIds) {
248-
Session session = sessions.get(id);
249-
if (session != null && session.getUri() != null) {
250-
uriToSessionIds.computeIfAbsent(session.getUri(), k -> new HashSet<>()).add(id);
245+
writeLock.lock();
246+
try {
247+
Map<URI, Set<SessionId>> uriToSessionIds = new HashMap<>();
248+
249+
for (SessionId id : sessionIds) {
250+
Session session = sessions.get(id);
251+
if (session != null && session.getUri() != null) {
252+
uriToSessionIds.computeIfAbsent(session.getUri(), k -> new HashSet<>()).add(id);
253+
}
251254
}
252-
}
253255

254-
for (SessionId id : sessionIds) {
255-
sessions.remove(id);
256-
}
256+
for (SessionId id : sessionIds) {
257+
sessions.remove(id);
258+
}
257259

258-
for (Map.Entry<URI, Set<SessionId>> entry : uriToSessionIds.entrySet()) {
259-
URI uri = entry.getKey();
260-
Set<SessionId> idsToRemove = entry.getValue();
260+
for (Map.Entry<URI, Set<SessionId>> entry : uriToSessionIds.entrySet()) {
261+
URI uri = entry.getKey();
262+
Set<SessionId> idsToRemove = entry.getValue();
261263

262-
sessionsByUri.computeIfPresent(
263-
uri,
264-
(k, existingIds) -> {
265-
existingIds.removeAll(idsToRemove);
266-
return existingIds.isEmpty() ? null : existingIds;
267-
});
264+
sessionsByUri.computeIfPresent(
265+
uri,
266+
(k, existingIds) -> {
267+
existingIds.removeAll(idsToRemove);
268+
return existingIds.isEmpty() ? null : existingIds;
269+
});
270+
}
271+
} finally {
272+
writeLock.unlock();
268273
}
269274
}
270275

0 commit comments

Comments
 (0)