Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElasticSearch Client: Wrapping of InterruptedException without restoring interrupted state of thread #68525

Closed
stefanocke opened this issue Feb 4, 2021 · 3 comments · Fixed by #68999
Labels
>bug :Clients/Java Low Level REST Client Minimal dependencies Java Client for Elasticsearch Team:Data Management Meta label for data/management team

Comments

@stefanocke
Copy link

stefanocke commented Feb 4, 2021

Elasticsearch version: 7.6.2

Here, java.lang.InterruptedException is catched and wrapped without restoring the interrupt state (i.e. calling Thread.currentThread().interrupt()).

https://github.com/elastic/elasticsearch/blob/master/client/rest/src/main/java/org/elasticsearch/client/RestClient.java#L842

private static Exception extractAndWrapCause(Exception exception) {
        if (exception instanceof InterruptedException) {
            throw new RuntimeException("thread waiting for the response was interrupted", exception);
        }

This is bad practice, since subsequent code might miss the fact that the thread is interrupted.

Similar issues have been submitted for other places before. See for example #4712

@stefanocke stefanocke added >bug needs:triage Requires assignment of a team area label labels Feb 4, 2021
@DaveCTurner DaveCTurner added :Clients/Java Low Level REST Client Minimal dependencies Java Client for Elasticsearch and removed needs:triage Requires assignment of a team area label labels Feb 4, 2021
@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Feb 4, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (Team:Core/Features)

@AlbusAndreus
Copy link

maybe try creating an instance boolean that is turned off when the exception is caught and the code that follows it can check if the boolean is true before executing certain code.

@stefanocke
Copy link
Author

stefanocke commented Feb 5, 2021

@AlbusAndreus , please see for example here for best practices:
https://www.ibm.com/developerworks/library/j-jtp05236/index.html

And there, especially the section "Don't swallow interrupts"

Basically you are right, but the boolean you are talking about must be Thread.isInterrupted().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Clients/Java Low Level REST Client Minimal dependencies Java Client for Elasticsearch Team:Data Management Meta label for data/management team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants