Skip to content

Commit b80c99b

Browse files
authored
Fork listener#onFailure in PrimaryReplicaSyncer (elastic#70506)
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 elastic#69949 Closes elastic#70407
1 parent d8a78b9 commit b80c99b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,24 @@ public void onResponse(ResyncReplicationResponse response) {
222222
@Override
223223
public void onFailure(Exception e) {
224224
if (closed.compareAndSet(false, true)) {
225-
listener.onFailure(e);
225+
executor.execute(new AbstractRunnable() {
226+
@Override
227+
public void onFailure(Exception ex) {
228+
e.addSuppressed(ex);
229+
230+
// We are on the generic threadpool so shouldn't be rejected, and listener#onFailure shouldn't throw anything,
231+
// so getting here should be impossible.
232+
assert false : e;
233+
234+
// Notify the listener on the current thread anyway, just in case.
235+
listener.onFailure(e);
236+
}
237+
238+
@Override
239+
protected void doRun() {
240+
listener.onFailure(e);
241+
}
242+
});
226243
}
227244
}
228245

0 commit comments

Comments
 (0)