Skip to content

Commit

Permalink
ARROW-7199: [Java] Fix ConcurrentModificationException in BaseAllocat…
Browse files Browse the repository at this point in the history
…or::getChildAllocators

synchronize on childAllocators map when iterating on its entries using keySet/entrySet views

Closes apache#5856 from pprudhvi/sync-basealloc and squashes the following commits:

052dd83 <Prudhvi Porandla> synchronise over childallocators while iterating on keyset view

Authored-by: Prudhvi Porandla <[email protected]>
Signed-off-by: Krisztián Szűcs <[email protected]>
  • Loading branch information
pprudhvi authored and kszucs committed Nov 18, 2019
1 parent 1e3545d commit ec50473
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ public BufferAllocator getParentAllocator() {

@Override
public Collection<BufferAllocator> getChildAllocators() {
return new HashSet<>(childAllocators.keySet());
synchronized (childAllocators) {
return new HashSet<>(childAllocators.keySet());
}
}

private static String createErrorMsg(final BufferAllocator allocator, final int rounded, final int requested) {
Expand Down Expand Up @@ -449,8 +451,10 @@ public synchronized void close() {
} else {
if (!childAllocators.isEmpty()) {
outstandingChildAllocators.append("Outstanding child allocators : \n");
for (final BaseAllocator childAllocator : childAllocators.keySet()) {
outstandingChildAllocators.append(String.format(" %s", childAllocator.toString()));
synchronized (childAllocators) {
for (final BaseAllocator childAllocator : childAllocators.keySet()) {
outstandingChildAllocators.append(String.format(" %s", childAllocator.toString()));
}
}
}
}
Expand Down

0 comments on commit ec50473

Please sign in to comment.