Skip to content

Commit 35fb8fe

Browse files
authored
Make the search endpoint for search application cancellable (#95539)
This commit ensures that the search is cancelled when the http channel is closed in the middle of a request
1 parent 9904fcf commit 35fb8fe

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/action/RestQuerySearchApplicationAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.rest.RestRequest;
1313
import org.elasticsearch.rest.Scope;
1414
import org.elasticsearch.rest.ServerlessScope;
15+
import org.elasticsearch.rest.action.RestCancellableNodeClient;
1516
import org.elasticsearch.rest.action.RestChunkedToXContentListener;
1617
import org.elasticsearch.xpack.application.EnterpriseSearch;
1718

@@ -45,7 +46,9 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
4546
} else {
4647
request = new SearchApplicationSearchRequest(searchAppName);
4748
}
48-
final SearchApplicationSearchRequest finalRequest = request;
49-
return channel -> client.execute(QuerySearchApplicationAction.INSTANCE, finalRequest, new RestChunkedToXContentListener<>(channel));
49+
return channel -> {
50+
RestCancellableNodeClient cancelClient = new RestCancellableNodeClient(client, restRequest.getHttpChannel());
51+
cancelClient.execute(QuerySearchApplicationAction.INSTANCE, request, new RestChunkedToXContentListener<>(channel));
52+
};
5053
}
5154
}

0 commit comments

Comments
 (0)