Skip to content

Making RestHighLevelClient async requests abortable #44802

Closed
@jillesvangurp

Description

@jillesvangurp

Describe the feature:

I was looking at how the asynchronous requests work in the RestHighLevelClient and noticed that there currently is no way to abort a request. Apache HttpClient has an abort() method but the Apache request is burried in an InternalRequest object in the RestHighLevelClient and not exposed.

What I'm looking for is a way to use Kotlin's suspendCancellableCoRoutine (see here for an explanation) with the client in my kotlin client. See here for how that works currently (uses the non cancellable suspendCoRoutine).

The advantage of this would be that Kotlin cancels the other subtasks in a co-routine context when one of them throws an error. The advantage of this would be not creating more connections to a hanging Elasticsearch in case you are doing multiple asynchronous calls, freeing up file handles of already running connections that are no longer relevant, etc.

From my limited understanding of the code base, it seems the abort method could be exposed from the InternalRequest, which then in turn could be exposed to the ActionRequest. So the user could create a request and then abort it later. And additional change that would make sense is to add an onAbort to the ActionListener interface.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions