From 73a0875b3dbf55432c7806146cf9c71fbd87326e Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 17 Mar 2021 15:10:04 +0000 Subject: [PATCH] Fork listener#onFailure in PrimaryReplicaSyncer We assert that the snapshot isn't closed on a transport thread, but we close it without forking off the transport thread in case of a failure. With this commit we fork on failure too. Relates #69949 Closes #70407 --- .../index/shard/PrimaryReplicaSyncer.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/shard/PrimaryReplicaSyncer.java b/server/src/main/java/org/elasticsearch/index/shard/PrimaryReplicaSyncer.java index ad34a1c4f8a7d..e001f1144d901 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/PrimaryReplicaSyncer.java +++ b/server/src/main/java/org/elasticsearch/index/shard/PrimaryReplicaSyncer.java @@ -222,7 +222,24 @@ public void onResponse(ResyncReplicationResponse response) { @Override public void onFailure(Exception e) { if (closed.compareAndSet(false, true)) { - listener.onFailure(e); + executor.execute(new AbstractRunnable() { + @Override + public void onFailure(Exception ex) { + e.addSuppressed(ex); + + // We are on the generic threadpool so shouldn't be rejected, and listener#onFailure shouldn't throw anything, + // so getting here should be impossible. + assert false : e; + + // Notify the listener on the current thread anyway, just in case. + listener.onFailure(e); + } + + @Override + protected void doRun() { + listener.onFailure(e); + } + }); } }