Skip to content

sync api: cancel queries when the calling thread is interrupted by always using the underlying HTTP client async api#1196

Closed
lovasoa wants to merge 2 commits intoelastic:mainfrom
lovasoa:codex/interrupt-sync-request-test
Closed

sync api: cancel queries when the calling thread is interrupted by always using the underlying HTTP client async api#1196
lovasoa wants to merge 2 commits intoelastic:mainfrom
lovasoa:codex/interrupt-sync-request-test

Conversation

@lovasoa
Copy link
Copy Markdown
Contributor

@lovasoa lovasoa commented Apr 1, 2026

This pr changes ElasticsearchTransportBase.performRequest to use httpClient.performRequestAsync instead of httpClient.performRequest. This allows it to always ensure the request is cancelled on interruption.

fixes #1195

@cla-checker-service
Copy link
Copy Markdown

cla-checker-service bot commented Apr 1, 2026

💚 CLA has been signed

lovasoa added a commit to lovasoa/elasticsearch-java that referenced this pull request Apr 1, 2026
When the thread is interrupted, cancel the underlying http request
instead of letting it run to completion.

This avoids runaway tasks running on the ES cluster while their client
has been interrupted and will never read the results.

fixes elastic#1195

This is an alternative to
elastic#1196 .
That pr fixed the issue with any http client, including those outside of
our control that have the same issue.
This PR focuses on our own rest client. The bug will still be present
when the library is used with other http clients that do not cancel
requests on interruption.
lovasoa added a commit to lovasoa/elasticsearch-java that referenced this pull request Apr 1, 2026
When the thread is interrupted, cancel the underlying http request
instead of letting it run to completion.

This avoids runaway tasks running on the ES cluster while their client
has been interrupted and will never read the results.

fixes elastic#1195

This is an alternative to
elastic#1196 .
That pr fixed the issue with any http client, including those outside of
our control that have the same issue.
This PR focuses on our own rest client. The bug will still be present
when the library is used with other http clients that do not cancel
requests on interruption.
@lovasoa lovasoa changed the title sync api: cancelled queries when the calling thread is interrupted sync api: cancel queries when the calling thread is interrupted by always using the underlying HTTP client async api Apr 3, 2026
l-trotta added a commit that referenced this pull request Apr 8, 2026
* rest5client: cancel http request on interruption

When the thread is interrupted, cancel the underlying http request
instead of letting it run to completion.

This avoids runaway tasks running on the ES cluster while their client
has been interrupted and will never read the results.

fixes #1195

This is an alternative to
#1196 .
That pr fixed the issue with any http client, including those outside of
our control that have the same issue.
This PR focuses on our own rest client. The bug will still be present
when the library is used with other http clients that do not cancel
requests on interruption.

* client.execute() stays inside the try block

addresses
#1197 (comment)

---------

Co-authored-by: Laura Trotta <153528055+l-trotta@users.noreply.github.com>
@l-trotta
Copy link
Copy Markdown
Contributor

l-trotta commented Apr 8, 2026

closing this in favor of #1197

@l-trotta l-trotta closed this Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in the sync api, queries are not cancelled when the calling thread is interrupted

2 participants