[
https://issues.apache.org/jira/browse/CXF-9271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18141446#comment-18141446
]
Freeman Yue Fang edited comment on CXF-9271 at 11/9/26, 5:01 PM:
-----------------------------------------------------------------
Hi [~reta],
I just reproduced with the test case and with the fix for CXF-9268
{code}
---
a/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/SharedInputBufferTest.java
+++
b/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/SharedInputBufferTest.java
@@ -27,10 +27,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
public class SharedInputBufferTest {
@@ -81,4 +84,38 @@ public class SharedInputBufferTest {
executor.shutdownNow();
}
}
+
+ @Test
+ public void testShutdownWakesUpConsumerWaitingForBufferToBeDrained()
throws Exception {
+ assertConsumerWokenUp(SharedInputBuffer::shutdown);
+ }
+
+ @Test
+ public void testCloseWakesUpConsumerWaitingForBufferToBeDrained() throws
Exception {
+ assertConsumerWokenUp(SharedInputBuffer::close);
+ }
+
+ private static void assertConsumerWokenUp(Consumer<SharedInputBuffer>
abort) throws Exception {
+ final SharedInputBuffer inbuf = new SharedInputBuffer(1024);
+ // A block larger than the buffer fills it, and with no reader
draining it the I/O thread
+ // waits until the reader has drained it or the response is aborted
+ final Thread io = new Thread(() -> {
+ try {
+ inbuf.consumeContent(ByteBuffer.allocate(4096), false);
+ } catch (IOException ex) {
+ // aborted
+ }
+ });
+ io.setDaemon(true);
+ io.start();
+ final long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
+ while (io.getState() != Thread.State.WAITING && System.nanoTime() <
deadline) {
+ Thread.sleep(10);
+ }
+ assertEquals(Thread.State.WAITING, io.getState());
+
+ abort.accept(inbuf);
+ io.join(TimeUnit.SECONDS.toMillis(10));
+ assertFalse("The I/O thread is still waiting for the buffer to be
drained", io.isAlive());
+ }
{code}
So the fix for CXF-9268 didn't cover this. And the suggested fix here seems
work.
Best Regards
Freeman
was (Author: ffang):
Hi [~reta],
I just verified with the test case
{code}
---
a/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/SharedInputBufferTest.java
+++
b/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/SharedInputBufferTest.java
@@ -27,10 +27,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
public class SharedInputBufferTest {
@@ -81,4 +84,38 @@ public class SharedInputBufferTest {
executor.shutdownNow();
}
}
+
+ @Test
+ public void testShutdownWakesUpConsumerWaitingForBufferToBeDrained()
throws Exception {
+ assertConsumerWokenUp(SharedInputBuffer::shutdown);
+ }
+
+ @Test
+ public void testCloseWakesUpConsumerWaitingForBufferToBeDrained() throws
Exception {
+ assertConsumerWokenUp(SharedInputBuffer::close);
+ }
+
+ private static void assertConsumerWokenUp(Consumer<SharedInputBuffer>
abort) throws Exception {
+ final SharedInputBuffer inbuf = new SharedInputBuffer(1024);
+ // A block larger than the buffer fills it, and with no reader
draining it the I/O thread
+ // waits until the reader has drained it or the response is aborted
+ final Thread io = new Thread(() -> {
+ try {
+ inbuf.consumeContent(ByteBuffer.allocate(4096), false);
+ } catch (IOException ex) {
+ // aborted
+ }
+ });
+ io.setDaemon(true);
+ io.start();
+ final long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
+ while (io.getState() != Thread.State.WAITING && System.nanoTime() <
deadline) {
+ Thread.sleep(10);
+ }
+ assertEquals(Thread.State.WAITING, io.getState());
+
+ abort.accept(inbuf);
+ io.join(TimeUnit.SECONDS.toMillis(10));
+ assertFalse("The I/O thread is still waiting for the buffer to be
drained", io.isAlive());
+ }
{code}
So the fix for CXF-9268 didn't cover this. And the suggested fix here seems
work.
Best Regards
Freeman
> http-hc5: SharedInputBuffer.consumeContent() can park the I/O reactor thread
> forever — close()/shutdown() never signal suspendInput
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: CXF-9271
> URL: https://issues.apache.org/jira/browse/CXF-9271
> Project: CXF
> Issue Type: Bug
> Components: Transports
> Affects Versions: 4.2.4
> Environment: Apache CXF 4.2.4 (also reproduces on 4.2.x)
> Module: rt/transports/http-hc5
> httpclient5 / httpcore5 5.4.x
> Reporter: Alexander Glazovskiy
> Assignee: Andriy Redko
> Priority: Critical
>
> SharedInputBuffer.consumeContent() waits on the suspendInput condition when
> the internal buffer is full, but close() and shutdown() only signal the other
> condition. If either method is called while a dispatch thread is parked in
> consumeContent(), that thread is never woken up and the I/O reactor
> permanently loses one of its threads.
> Under load this compounds into complete connection-pool starvation and
> OutOfMemoryError.
> It can be reproduced with any SOAP call whose response body is larger than
> chunkLength, where the subscription is cancelled while the body is still
> being received.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)