Skip to content

Commit 7692b60

Browse files
Fix ClusterDisruptionIT#testAckedIndexing (#37853)
* Stop threads before logging the list of exceptions * For the broken case of concurrent iteration in the finally block and the threads not having shut down, use `CopyOnWriteArrayList` to have concurrency safe iteration * Closes #37810
1 parent 5a9dadb commit 7692b60

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.Collections;
5151
import java.util.List;
5252
import java.util.concurrent.ConcurrentHashMap;
53+
import java.util.concurrent.CopyOnWriteArrayList;
5354
import java.util.concurrent.CountDownLatch;
5455
import java.util.concurrent.Semaphore;
5556
import java.util.concurrent.TimeUnit;
@@ -84,7 +85,6 @@ public class ClusterDisruptionIT extends AbstractDisruptionTestCase {
8485
"org.elasticsearch.discovery:TRACE,org.elasticsearch.action.support.replication:TRACE," +
8586
"org.elasticsearch.cluster.service:TRACE,org.elasticsearch.indices.recovery:TRACE," +
8687
"org.elasticsearch.indices.cluster:TRACE,org.elasticsearch.index.shard:TRACE")
87-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37810")
8888
public void testAckedIndexing() throws Exception {
8989

9090
final int seconds = !(TEST_NIGHTLY && rarely()) ? 1 : 5;
@@ -109,7 +109,7 @@ public void testAckedIndexing() throws Exception {
109109
List<Semaphore> semaphores = new ArrayList<>(nodes.size());
110110
final AtomicInteger idGenerator = new AtomicInteger(0);
111111
final AtomicReference<CountDownLatch> countDownLatchRef = new AtomicReference<>();
112-
final List<Exception> exceptedExceptions = Collections.synchronizedList(new ArrayList<Exception>());
112+
final List<Exception> exceptedExceptions = new CopyOnWriteArrayList<>();
113113

114114
logger.info("starting indexers");
115115
try {
@@ -215,19 +215,19 @@ public void testAckedIndexing() throws Exception {
215215
logger.info("done validating (iteration [{}])", iter);
216216
}
217217
} finally {
218+
logger.info("shutting down indexers");
219+
stop.set(true);
220+
for (Thread indexer : indexers) {
221+
indexer.interrupt();
222+
indexer.join(60000);
223+
}
218224
if (exceptedExceptions.size() > 0) {
219225
StringBuilder sb = new StringBuilder();
220226
for (Exception e : exceptedExceptions) {
221227
sb.append("\n").append(e.getMessage());
222228
}
223229
logger.debug("Indexing exceptions during disruption: {}", sb);
224230
}
225-
logger.info("shutting down indexers");
226-
stop.set(true);
227-
for (Thread indexer : indexers) {
228-
indexer.interrupt();
229-
indexer.join(60000);
230-
}
231231
}
232232
}
233233

0 commit comments

Comments
 (0)