rest5client: cancel http request on interruption in the sync api#1197
Merged
l-trotta merged 3 commits intoelastic:mainfrom Apr 8, 2026
Merged
Conversation
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.
Contributor
Author
|
If someone has time, could you please review this ? @Mpdreamz maybe ? |
Member
|
Hey @lovasoa I am no longer on the clients team but I am sure this will be handled soon! |
Contributor
|
@lovasoa could you make a small change? client.execute() should stay inside the try block, as it was before the changes. |
lovasoa
added a commit
to lovasoa/elasticsearch-java
that referenced
this pull request
Apr 7, 2026
Contributor
Author
|
@l-trotta I made the change. I think wrapping potential exceptions thrown by |
532873a to
28de62d
Compare
l-trotta
approved these changes
Apr 8, 2026
Contributor
Author
|
Thank you ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a thread running a synchronous Rest5Client request 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, but required using
performRequestAsyncunder the hood even on http clients that may not have the issue.This PR focuses on our own Rest5 client and fixes the issue at a lower level. Users of the org.elasticsearch.client.RestClient (which is not defined in this repo) will still be affected by the issue.