Skip to content

Commit 191c18d

Browse files
authored
Fix concurrency bug in DrillSidewaysQuery (apache#2518)
1 parent 2ce469c commit 191c18d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22+
import java.util.Collections;
2223
import java.util.Comparator;
2324
import java.util.List;
2425
import java.util.Objects;
@@ -65,12 +66,15 @@ class DrillSidewaysQuery extends Query {
6566
FacetsCollectorManager[] drillSidewaysCollectorManagers,
6667
Query[] drillDownQueries,
6768
boolean scoreSubDocsAtOnce) {
69+
// Note that the "managed" facet collector lists are synchronized here since bulkScorer()
70+
// can be invoked concurrently and needs to remain thread-safe. We're OK with synchronizing
71+
// on the whole list as contention is expected to remain very low:
6872
this(
6973
baseQuery,
7074
drillDownCollectorManager,
7175
drillSidewaysCollectorManagers,
72-
new ArrayList<>(),
73-
new ArrayList<>(),
76+
Collections.synchronizedList(new ArrayList<>()),
77+
Collections.synchronizedList(new ArrayList<>()),
7478
drillDownQueries,
7579
scoreSubDocsAtOnce);
7680
}

0 commit comments

Comments
 (0)