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

Improve handling of InterruptedException across codebase #2398

Closed
rohanKanojia opened this issue Aug 12, 2020 · 2 comments · Fixed by #2429
Closed

Improve handling of InterruptedException across codebase #2398

rohanKanojia opened this issue Aug 12, 2020 · 2 comments · Fixed by #2429

Comments

@rohanKanojia
Copy link
Member

We can clearly see in Sonar Bug report that there are lots of places in code where we're not handling InterruptedException properly. We're simply doing multi-catch and ignoring InterruptedException . For example, take a look at this code block:

private L listRequestHelper(URL url) {
try {
HttpUrl.Builder requestUrlBuilder = HttpUrl.get(url).newBuilder();
addQueryStringParam(requestUrlBuilder, "labelSelector", getLabelQueryParam());
addQueryStringParam(requestUrlBuilder, "fieldSelector", getFieldQueryParam());
Request.Builder requestBuilder = new Request.Builder().get().url(requestUrlBuilder.build());
L answer = handleResponse(requestBuilder, listType);
updateApiVersion(answer);
return answer;
} catch (InterruptedException | ExecutionException | IOException e) {
throw KubernetesClientException.launderThrowable(forOperationType("list"), e);
}
}

Usually, when a thread is interrupted, whoever is interrupting the thread, wants the thread to exit what it's currently doing. I think we should refactor all these places like this:

try{
    //some code
} catch (InterruptedException ie) {
    Thread.currentThread().interrupt();
    throw KubernetesClientException.launderThrowable(forOperationType("list"), e);
} catch (ExecutionException | IOException e) {
    throw KubernetesClientException.launderThrowable(forOperationType("list"), e);
}
@Shivkumar13
Copy link
Contributor

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants