Skip to content

Commit 278e967

Browse files
authored
Fix infinite loop when RefCountedSharedArena's underlying Arena#close fails due to concurrent usage of segments (#15112)
1 parent ec369d0 commit 278e967

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lucene/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ Bug Fixes
306306
resulted in query branches being wrongly ignored if the QueryIndex was
307307
built by a different JVM. (Luke Kot-Zaniewski)
308308

309+
* GITHUB#15106: Fix infinite loop when RefCountedSharedArena's underlying
310+
Arena#close fails due to concurrent usage of segments. (Uwe Schindler)
311+
309312
Build
310313
---------------------
311314
* Upgrade forbiddenapis to version 3.9. (Uwe Schindler)

lucene/core/src/java/org/apache/lucene/store/RefCountedSharedArena.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ final class RefCountedSharedArena implements Arena {
5050
private static final int ACQUIRE_DECREMENT = REMAINING_UNIT - 1; // 0xffff
5151

5252
private final String segmentName;
53+
54+
// onClose could be called multiple times when the inner Arena's close fails with
55+
// IllegalStateException
5356
private final Runnable onClose;
57+
5458
private final Arena arena;
5559

5660
// high 16 bits contain the total remaining acquires; monotonically decreasing
@@ -99,14 +103,10 @@ boolean acquire() {
99103

100104
/** Decrements the ref count. */
101105
void release() {
102-
int value;
103106
while (true) {
104-
value = state.get();
107+
final int value = state.get();
105108
final int count = value & 0xFFFF;
106-
if (count == 0) {
107-
throw new IllegalStateException(value == CLOSED ? "closed" : "nothing to release");
108-
}
109-
final int newValue = count == 1 ? CLOSED : value - 1;
109+
final int newValue = count <= 1 ? CLOSED : value - 1;
110110
if (this.state.compareAndSet(value, newValue)) {
111111
if (newValue == CLOSED) {
112112
onClose.run();

0 commit comments

Comments
 (0)