github-advanced-security[bot] commented on code in PR #20522:
URL: https://github.com/apache/druid/pull/20522#discussion_r4219323208
##########
processing/src/test/java/org/apache/druid/java/util/http/client/FriendlyServersTest.java:
##########
@@ -753,4 +760,198 @@
lifecycle.stop();
}
}
+
+ /**
+ * An abort that arrives once the response is complete must not close the
channel: it is back in the pool, and the
+ * next request may already be on it.
+ */
+ @Test
+ public void testAbortAfterCompletionLeavesThePooledChannelOpen() throws
Exception
+ {
+ final ExecutorService exec = Executors.newSingleThreadExecutor();
+ final ServerSocket serverSocket = new ServerSocket(0);
+ final BlockingQueue<String> wire = new LinkedBlockingQueue<>();
+ serveChunkedFromWire(exec, serverSocket, wire);
+
+ final Lifecycle lifecycle = new Lifecycle();
+ try {
+ final HttpClient client = HttpClientInit.createClient(
+ HttpClientConfig.builder().withNumConnections(1).build(),
+ lifecycle
+ );
+ final Request request = new Request(
+ HttpMethod.GET,
+ new URL(StringUtils.format("http://localhost:%d/",
serverSocket.getLocalPort()))
+ );
+
+ final CapturingTrafficCop<StringFullResponseHolder,
StringFullResponseHolder> first =
+ new CapturingTrafficCop<>(new
StringFullResponseHandler(StandardCharsets.UTF_8));
+ final ListenableFuture<StringFullResponseHolder> firstResponse =
client.go(request, first);
+ wire.put(CHUNKED_OK + chunk("a") + LAST_CHUNK);
+ Assertions.assertEquals("a", firstResponse.get(30,
TimeUnit.SECONDS).getContent());
+
+ first.trafficCop.get().abort();
+
+ // The server answers on its only connection, so the second request
succeeds only if it reuses the first's.
+ final ListenableFuture<StringFullResponseHolder> secondResponse =
+ client.go(request, new
StringFullResponseHandler(StandardCharsets.UTF_8));
+ wire.put(CHUNKED_OK + chunk("b") + LAST_CHUNK);
+ Assertions.assertEquals("b", secondResponse.get(30,
TimeUnit.SECONDS).getContent());
+ }
+ finally {
+ exec.shutdownNow();
+ serverSocket.close();
+ lifecycle.stop();
+ }
+ }
+
+ /**
+ * A resume that arrives once the response is complete must not touch the
channel: it is back in the pool, and the
+ * next request on it may have suspended reads.
+ */
+ @Test
+ public void testResumeAfterCompletionLeavesTheNextRequestSuspended() throws
Exception
+ {
+ final ExecutorService exec = Executors.newSingleThreadExecutor();
+ final ServerSocket serverSocket = new ServerSocket(0);
+ final BlockingQueue<String> wire = new LinkedBlockingQueue<>();
+ serveChunkedFromWire(exec, serverSocket, wire);
+
+ final Lifecycle lifecycle = new Lifecycle();
+ try {
+ final HttpClient client = HttpClientInit.createClient(
+ HttpClientConfig.builder().withNumConnections(1).build(),
+ lifecycle
+ );
+ final Request request = new Request(
+ HttpMethod.GET,
+ new URL(StringUtils.format("http://localhost:%d/",
serverSocket.getLocalPort()))
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [URL.URL](1) should be avoided because it has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/12046)
##########
processing/src/test/java/org/apache/druid/java/util/http/client/FriendlyServersTest.java:
##########
@@ -753,4 +760,198 @@
lifecycle.stop();
}
}
+
+ /**
+ * An abort that arrives once the response is complete must not close the
channel: it is back in the pool, and the
+ * next request may already be on it.
+ */
+ @Test
+ public void testAbortAfterCompletionLeavesThePooledChannelOpen() throws
Exception
+ {
+ final ExecutorService exec = Executors.newSingleThreadExecutor();
+ final ServerSocket serverSocket = new ServerSocket(0);
+ final BlockingQueue<String> wire = new LinkedBlockingQueue<>();
+ serveChunkedFromWire(exec, serverSocket, wire);
+
+ final Lifecycle lifecycle = new Lifecycle();
+ try {
+ final HttpClient client = HttpClientInit.createClient(
+ HttpClientConfig.builder().withNumConnections(1).build(),
+ lifecycle
+ );
+ final Request request = new Request(
+ HttpMethod.GET,
+ new URL(StringUtils.format("http://localhost:%d/",
serverSocket.getLocalPort()))
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [URL.URL](1) should be avoided because it has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/12045)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]