You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "abhi-ksolves (via GitHub)" <gi...@apache.org> on 2024/06/11 12:03:42 UTC
[PR] Fix Missing thread interrupt call in RestClient class [kafka]
abhi-ksolves opened a new pull request, #16282:
URL: https://github.com/apache/kafka/pull/16282
In RestClient class, httpRequest is being called with different threads. An InterruptedException is used to handle specific exceptions in case of failure. It's a good practice to call Thread.currentThread().interrupt() so the rest of the code knows the thread was interrupted. A separate catch block is added to handle InterruptedException & interrupted the current thread.
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16076: Fix Missing thread interrupt call in RestClient class [kafka]
Posted by "gharris1727 (via GitHub)" <gi...@apache.org>.
gharris1727 commented on PR #16282:
URL: https://github.com/apache/kafka/pull/16282#issuecomment-2163777340
Supersedes #15110
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16076: Fix Missing thread interrupt call in RestClient class [kafka]
Posted by "abhi-ksolves (via GitHub)" <gi...@apache.org>.
abhi-ksolves commented on code in PR #16282:
URL: https://github.com/apache/kafka/pull/16282#discussion_r1637685575
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestClient.java:
##########
@@ -189,9 +190,13 @@ private <T> HttpResponse<T> httpRequest(HttpClient client, String url, String me
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"Unexpected status code when handling forwarded request: " + responseCode);
}
- } catch (IOException | InterruptedException | TimeoutException | ExecutionException e) {
+ } catch (IOException | TimeoutException | ExecutionException e) {
log.error("IO error forwarding REST request to {} :", url, e);
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR, "IO Error trying to forward REST request: " + e.getMessage(), e);
+ } catch (InterruptedException e) {
+ log.error("Thread was interrupted forwarding REST request to {} :", url, e);
+ Thread.currentThread().interrupt();
Review Comment:
this test case seems suitable i have added the same
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16076: Fix Missing thread interrupt call in RestClient class [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #16282:
URL: https://github.com/apache/kafka/pull/16282#issuecomment-2166982488
all failed tests pass on my local. will merge it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16076: Fix Missing thread interrupt call in RestClient class [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #16282:
URL: https://github.com/apache/kafka/pull/16282#discussion_r1637109956
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestClient.java:
##########
@@ -189,9 +190,13 @@ private <T> HttpResponse<T> httpRequest(HttpClient client, String url, String me
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"Unexpected status code when handling forwarded request: " + responseCode);
}
- } catch (IOException | InterruptedException | TimeoutException | ExecutionException e) {
+ } catch (IOException | TimeoutException | ExecutionException e) {
log.error("IO error forwarding REST request to {} :", url, e);
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR, "IO Error trying to forward REST request: " + e.getMessage(), e);
+ } catch (InterruptedException e) {
+ log.error("Thread was interrupted forwarding REST request to {} :", url, e);
+ Thread.currentThread().interrupt();
Review Comment:
> I believe it is not required because this httpRequest is an overloaded method that is only used by another httpRequest method invoked in RestClientTest.java.
not sure whether I catch your point. It seems the `httpRequest` you fix is used by other variety `httpRequest` of `RestClient`. It is used by production, and so it is worthwhile to have a simple test case in `RestClientTest`. For example:
```java
@Test
public void testInterruptCall() throws ExecutionException, InterruptedException, TimeoutException {
Request req = mock(Request.class);
doThrow(new InterruptedException()).when(req).send();
doReturn(req).when(req).header(anyString(), anyString());
doReturn(req).when(httpClient).newRequest(anyString());
ConnectRestException e = assertThrows(ConnectRestException.class, () -> httpRequest(
httpClient, MOCK_URL, TEST_METHOD, TEST_TYPE, TEST_SIGNATURE_ALGORITHM
));
assertIsInternalServerError(e);
assertInstanceOf(InterruptedException.class, e.getCause());
assertTrue(Thread.interrupted());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16076: Fix Missing thread interrupt call in RestClient class [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #16282:
URL: https://github.com/apache/kafka/pull/16282
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix Missing thread interrupt call in RestClient class [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #16282:
URL: https://github.com/apache/kafka/pull/16282#discussion_r1635307088
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestClient.java:
##########
@@ -189,9 +190,13 @@ private <T> HttpResponse<T> httpRequest(HttpClient client, String url, String me
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"Unexpected status code when handling forwarded request: " + responseCode);
}
- } catch (IOException | InterruptedException | TimeoutException | ExecutionException e) {
+ } catch (IOException | TimeoutException | ExecutionException e) {
log.error("IO error forwarding REST request to {} :", url, e);
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR, "IO Error trying to forward REST request: " + e.getMessage(), e);
+ } catch (InterruptedException e) {
+ log.error("Thread was interrupted forwarding REST request to {} :", url, e);
+ Thread.currentThread().interrupt();
Review Comment:
Could you please give a try of adding unit test?
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestClient.java:
##########
@@ -77,7 +77,7 @@ HttpClient httpClient(SslContextFactory.Client sslContextFactory) {
* @return The deserialized response to the HTTP request, containing null if no data is expected or returned.
*/
public <T> HttpResponse<T> httpRequest(String url, String method, HttpHeaders headers, Object requestBodyData,
- TypeReference<T> responseFormat) {
Review Comment:
Could you please revert those unrelated changes? It makes this PR smaller :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16076: Fix Missing thread interrupt call in RestClient class [kafka]
Posted by "abhi-ksolves (via GitHub)" <gi...@apache.org>.
abhi-ksolves commented on code in PR #16282:
URL: https://github.com/apache/kafka/pull/16282#discussion_r1636020686
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestClient.java:
##########
@@ -189,9 +190,13 @@ private <T> HttpResponse<T> httpRequest(HttpClient client, String url, String me
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"Unexpected status code when handling forwarded request: " + responseCode);
}
- } catch (IOException | InterruptedException | TimeoutException | ExecutionException e) {
+ } catch (IOException | TimeoutException | ExecutionException e) {
log.error("IO error forwarding REST request to {} :", url, e);
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR, "IO Error trying to forward REST request: " + e.getMessage(), e);
+ } catch (InterruptedException e) {
+ log.error("Thread was interrupted forwarding REST request to {} :", url, e);
+ Thread.currentThread().interrupt();
Review Comment:
I believe it is not required because this httpRequest is an overloaded method that is only used by another httpRequest method invoked in RestClientTest.java.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org