From ae84c324e6323f91b7eed3a1f2df532d186220a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Cea=20Fontenla?= Date: Wed, 21 May 2025 13:45:45 +0200 Subject: [PATCH] ESQL: Unmute test and reuse blockFactory to avoid concurrently modifying the test factories list (#128211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/elastic/elasticsearch/issues/128092 The error happens inside an ArrayList.add(), and it's a concurrency-related one. The stacktrace is quite explicative: ``` java.lang.ArrayIndexOutOfBoundsException: Index 34 out of bounds for length 33 at java.util.ArrayList.add(ArrayList.java:485) at org.elasticsearch.compute.test.ComputeTestCase.blockFactory(ComputeTestCase.java:62) at org.elasticsearch.compute.aggregation.GroupingAggregatorFunctionTestCase$4$1$1.addBlock(GroupingAggregatorFunctionTestCase.java:659) ``` We were creating new blockFactories() inside the aggregator, which was being called concurrently with different drivers. As `blockFactory()` adds it to a static ArrayList, it was sometimes throwing. The bug only affects tests. Potentially, all grouping aggregators tests. --- .../compute/aggregation/GroupingAggregatorFunctionTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/GroupingAggregatorFunctionTestCase.java b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/GroupingAggregatorFunctionTestCase.java index d82a8487b5390..9839103aced0a 100644 --- a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/GroupingAggregatorFunctionTestCase.java +++ b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/GroupingAggregatorFunctionTestCase.java @@ -651,7 +651,7 @@ public AddInput prepareProcessPage(SeenGroupIds ignoredSeenGroupIds, Page page) @Override public void add(int positionOffset, IntBlock groupIds) { for (int offset = 0; offset < groupIds.getPositionCount(); offset += emitChunkSize) { - try (IntBlock.Builder builder = blockFactory().newIntBlockBuilder(emitChunkSize)) { + try (IntBlock.Builder builder = driverContext.blockFactory().newIntBlockBuilder(emitChunkSize)) { int endP = Math.min(groupIds.getPositionCount(), offset + emitChunkSize); for (int p = offset; p < endP; p++) { int start = groupIds.getFirstValueIndex(p);