Skip to content

Commit 3cf0832

Browse files
committed
Handle AlreadyClosedException when bumping primary term
If the shard is already closed while bumping the primary term, this can result in an AlreadyClosedException to be thrown. As we use asyncBlockOperations, the exception will be thrown on a thread from the generic thread pool and end up in the uncaught exception handler, failing our tests. Relates to #32442
1 parent 66edba2 commit 3cf0832

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,13 @@ private <E extends Exception> void bumpPrimaryTerm(long newPrimaryTerm, final Ch
22292229
onBlocked.run();
22302230
}
22312231
},
2232-
e -> failShard("exception during primary term transition", e));
2232+
e -> {
2233+
try {
2234+
failShard("exception during primary term transition", e);
2235+
} catch (AlreadyClosedException ace) {
2236+
// ignore, shard is already closed
2237+
}
2238+
});
22332239
pendingPrimaryTerm = newPrimaryTerm;
22342240
termUpdated.countDown();
22352241
}

0 commit comments

Comments
 (0)