Skip to content

Commit

Permalink
Fix SO-Error in SearchWithRandomDisconnectsIT (elastic#122593)
Browse files Browse the repository at this point in the history
Obvious SO exception possibilitiy if we encounter exceptions back to back in the callback.
Use promise style pattern instead of callback in the individual loops to limit stack-depth
(this should be good enough for a fix, technically you could still run into very deep stacks
if the search completes between the `isDone` check and adding the listener back-to-back
a couple times but practically this should be good enough since all the instant-done situations
are from the search fully failing outright.

closes elastic#116175
  • Loading branch information
original-brownbear authored Feb 14, 2025
1 parent 95f8454 commit fd25d3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ tests:
- class: org.elasticsearch.action.search.SearchPhaseControllerTests
method: testProgressListener
issue: https://github.com/elastic/elasticsearch/issues/116149
- class: org.elasticsearch.search.basic.SearchWithRandomDisconnectsIT
method: testSearchWithRandomDisconnects
issue: https://github.com/elastic/elasticsearch/issues/116175
- class: org.elasticsearch.xpack.deprecation.DeprecationHttpIT
method: testDeprecatedSettingsReturnWarnings
issue: https://github.com/elastic/elasticsearch/issues/108628
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ListenableFuture;
import org.elasticsearch.discovery.AbstractDisruptionTestCase;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
Expand Down Expand Up @@ -67,11 +68,15 @@ public void onFailure(Exception e) {
}

private void runMoreSearches() {
if (done.get() == false) {
prepareRandomSearch().execute(this);
} else {
finishFuture.onResponse(null);
while (done.get() == false) {
final ListenableFuture<SearchResponse> f = new ListenableFuture<>();
prepareRandomSearch().execute(f);
if (f.isDone() == false) {
f.addListener(this);
return;
}
}
finishFuture.onResponse(null);
}
});
}
Expand Down

0 comments on commit fd25d3b

Please sign in to comment.