From 3cf08326ab025aa7f9ac81e70c38313c625e19f5 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Mon, 6 Aug 2018 08:34:38 +0200 Subject: [PATCH] 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 --- .../java/org/elasticsearch/index/shard/IndexShard.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index f29f17a46dc..9131055bcd9 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -2229,7 +2229,13 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl onBlocked.run(); } }, - e -> failShard("exception during primary term transition", e)); + e -> { + try { + failShard("exception during primary term transition", e); + } catch (AlreadyClosedException ace) { + // ignore, shard is already closed + } + }); pendingPrimaryTerm = newPrimaryTerm; termUpdated.countDown(); }