Skip to content

Commit

Permalink
No more stack overflow avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
henningandersen committed May 31, 2024
1 parent df049ea commit d279bfa
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ protected void handleInternalSendException(
}
final var sendRequestException = new SendRequestTransportException(node, action, failure);
final var handler = contextToNotify.handler();
final var executor = getAvoidStackOverflowExecutor(handler.executor());
final var executor = getInternalSendExceptionExecutor(handler.executor());
executor.execute(new AbstractRunnable() {
@Override
protected void doRun() {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ public void onRejection(Exception e) {
});
}

private Executor getAvoidStackOverflowExecutor(Executor handlerExecutor) {
private Executor getInternalSendExceptionExecutor(Executor handlerExecutor) {
if (lifecycle.stoppedOrClosed()) {
// too late to try and dispatch anywhere else, let's just use the calling thread
return EsExecutors.DIRECT_EXECUTOR_SERVICE;
Expand Down Expand Up @@ -1354,8 +1354,9 @@ public void onConnectionClosed(Transport.Connection connection) {
NodeDisconnectedException exception = new NodeDisconnectedException(connection.getNode(), holderToNotify.action());

TransportResponseHandler<?> handler = holderToNotify.handler();
// Callback that an exception happened, but on a different thread since we don't want handlers to worry about stack overflows.
final var executor = getAvoidStackOverflowExecutor(handler.executor());
// we used to fork to a different thread always to avoid stack overflows, but we avoid doing that now, expecting handlers
// to handle that themselves instead.
final var executor = handler.executor();
if (executor == EsExecutors.DIRECT_EXECUTOR_SERVICE) {
handler.handleException(exception);
} else {
Expand Down

0 comments on commit d279bfa

Please sign in to comment.