From e5a1dac523161e6de05794e67a3ce59039e15bd6 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 ea0239aae450d..7509dd86344d2 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -2264,7 +2264,13 @@ private void bumpPrimaryTerm(long newPrimaryTerm, final Ch 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(); }